No description, website, or topics provided.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
test
.gitignore
.npmignore
.travis.yml
README.md
index.js
package.json

README.md

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