-
-
Save gilligan/cda8d69f8cad5bd9643f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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