node-either-monad

1.0.3 • Public • Published

node-either-monad

Build Status

Either monad, good pattern to use when you have a function that may returns totally two different types

install

npm install --save node-either-monad

usage

const either = require('node-either-monad')
 
let left = either.left(1) // left
let right = either.right('data') //right
 
left.isLeft() // true
right.isRight() // true
 
let dataFolded = left.fold(x => x + 1, y => y + '-k'); // 2
let dataFolded = right.fold(x => x + 1, y => y + '-k'); // data-k
 
let left.swap() /// returns right with the same data
let right.swap() /// returns left with the same data
 
left.a // data of the left side
right.b // data of the right side
 

Dependencies (0)

    Dev Dependencies (3)

    Package Sidebar

    Install

    npm i node-either-monad

    Weekly Downloads

    3

    Version

    1.0.3

    License

    SEE LICENSE IN LICENSE.md

    Last publish

    Collaborators

    • kfiron