Last active
February 11, 2017 00:00
-
-
Save evilsoft/e0ca1a88d4b96cd753fcd3a6cf2c4c95 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const { | |
Either, coalesce, compose, | |
constant, identity, ifElse, | |
isString, map | |
} = require('crocks') | |
const { Left, Right } = Either | |
// onlyStrings : a -> Either Number String | |
const onlyStrings = | |
ifElse(isString, Right, constant(Left(0))) | |
// shout : String -> String | |
const shout = | |
str => str.toUpperCase() | |
// flow : a -> Either _ String | |
const flow = compose( | |
coalesce(constant('[default]'), identity), | |
map(shout), | |
onlyStrings | |
) | |
console.log(flow(3)) // Right "[default]" | |
console.log(flow('three')) // Right "THREE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment