1.0.0-beta • Published 5 years ago
monatic v1.0.0-beta
Monatic ·
✨Type-safe and pragmatic Monads for TypeScript ✨
This library has been designed with type safety and usability in mind. You're encouraged to enable strictNullChecks
in your TypeScript compiler options to raise null
or undefined
misuses at compile time. From TypeScript documentation:
In strict null checking mode, the null and undefined values are not in the domain of every type and are only assignable to themselves and any (the one exception being that undefined is also assignable to void).
Install
Install with npm:
$ npm install monatic --save
Install with yarn:
$ yarn add monatic
Option
import { from, Some, None, Option } from "monatic";
const random = (): number | undefined => {
const value = Math.floor(Math.random() * 100); // generates a random number between [0,100[
return value % 2 === 0 ? value : undefined;
};
// Will be 10 if random value is undefined, value * 2 otherwise
const x = from(random())
.map(v => v * 2)
.getOrElse(10);
Contributing
Scripts
clean
: Remove generated fileslint:src
: Lint src files with ESLintlint:test
: Lint test files with ESLintbuild:src
: Compile srcbuild:test
: Compile testformat
: Format files with Prettiertest
: Run tests with Jest
License
1.0.0-beta
5 years ago