Skip to content

Instantly share code, notes, and snippets.

@gilligan
Created May 21, 2015 20:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gilligan/cda8d69f8cad5bd9643f to your computer and use it in GitHub Desktop.
Save gilligan/cda8d69f8cad5bd9643f to your computer and use it in GitHub Desktop.
var R = require('ramda');
// isLeft :: Either a b -> bool
var isLeft = function(val) {
return val.chain(R.identity) === val;
};
// isLeft :: Either a b -> bool
var isRight = R.compose(R.not,isLeft);
// either :: Either a b -> (a -> c) -> (b -> c) -> c
var either = function(x, leftF, rightF) {
return isRight(x) ? x.chain(rightF) : leftF(x.value);
};
module.exports.either = either;
module.exports.isLeft = isLeft;
module.exports.isRight = isRight;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment