js-monadic
Monad with do notation in Javascript, using ES6 generators.
Installing
Using npm:
$ npm install js-monadic
Using yarn:
$ yarn add js-monadic
Using unpkg CDN:
Usage
const Monad = // Unit/Return function of the monad { // ...} // Bind function of the monad { // ...} const MyMonad = // Same as calling unit(...)const val = MyMonad
Example
Option / Maybe
// type Option<T> = { some: T } | nullconst Option = const foo = Option// foo = { some: 6 } const bar = Option// bar = null
Result / Either
// type Result<T> = { ok: T } | { error: Error }const Result = const foo = Result// foo = { ok: 3 } const bar = Result// bar = { error: Error('Bad object') }
Promise
// type Future<T> = Promise<T>const Future = const foo = Future// foo = Promise { 3 } const bar = Future// bar = Promise { <rejected> 'Bad object' }