A set of monadic data types
npm install monadical

_A small set of monadic data types to get you going functionally, with some optional extras_
Monadical provides data-types and functions such as Either or curry, allowing you to compose operations originating from different context such as generators or monads, with safety in mind.
To install the latest stable version, run either of the following via a terminal:
_using npm_
``shell script`
npm install monadical
_using yarn_
`shell script`
yarn add monadicalUsage & Compatibility
The project is currently written in Typescript, targeting version 3.6.x compiling down to es5. Note: CommonJS is the supported target, future work includes adding UMD support.
Using ES6, you can use the following import syntax:
`js`
import Either, { Left, Right } from 'monadical/either';
So, to import the Maybe data-type with composing functions, you would write the following using ES6:`js
import Maybe from 'monadical/maybe';
import compose from 'monadical/compose';
import chainC from 'monadical/chainC';
import isNumber from 'monadical/isNumber';
const add10 = amount => Maybe.nullable(isNumber(amount) ? amount + 10 : void 0);
const safelyAdd10 = compose(chainC(x => My amount is now: ${x}), add10);
console.assert(safelyAdd10(20) === 'My amount is now: 30')
console.assert(safelyAdd10(null) === void 0)
`
#### Container
Operations:
- get: (): T(f: (x: T) => U): Container
- map: (): Container
- join: (value: U): Container
- _static_ of:
#### Maybe
Operations:
- isNothing: (): boolean(): boolean
- isJust:
- _static_ just:
- _static_ nothing:
- _static_ of:
- _static_ nullable:
#### Just
Operations:
- isNothing: (): boolean(): boolean
- isJust: (): J
- get value: (func: (a: J) => J): Just
- map:
- chain: (_: any): J
- getOrElse:
- filter:
#### Nothing
Operations:
- isNothing: (): boolean(): boolean
- isJust: (_: any): Nothing
- map: (_: any): N
- chain:
- getOrElse: (_: any): Nothing
- filter:
#### Either
Operations:
- get value: (): T
- _static_ left:
- _static_ right:
- _static_ of:
- _static_ nullable:
#### Left
Operations:
- isRight: (): boolean(): boolean
- isLeft:
- map: (defaultVal: any): any
- getOrElse: (func: (val: L) => any): any
- orElse:
- chain: (func: (val: L) => Error): R | Error
- getOrElseThrow: (func: (val: R) => boolean): this
- filter:
#### Right
Operations:
- get value: (): R(): boolean
- isRight: (): boolean
- isLeft:
- map:
- getOrElse: (func: (val: R) => any): this
- orElse:
- chain: (func: (val: L | R) => Error): R | Error
- getOrElseThrow: (func: (val: R) => boolean): Either
- filter:
#### IO:
Operations:
- map: (func: Func1): IO(func: Func1Optional): any
- chain: (): any
- run: (val: U): IO
- _static_ of:
- _static_ from: (val: U): IO
- _static_ lift:
#### Empty
Operations:
- map: (_: any): void(_: any): Empty
- fmap:
- mapC: MapC = {
};
- chainC: ChainC = {
};
- getOrElseC: GetOrElseC = {
};
- mapG: MapG = {
};
- chainG: ChainG = {
};
- extractG: ExtractG = {
- safeHandleErrorG: SafeHandleErrorG = {
};
- safeUnpackG: SafeUnpackG = {
};`