Last active
October 30, 2018 15:39
-
-
Save Nauthiz-Jera/28d959700b00269d769679339b4f7579 to your computer and use it in GitHub Desktop.
Playing with Folktale
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 = folktale.result; | |
const Maybe = folktale.maybe; | |
const {task} = folktale.concurrency; | |
const fetchResult = (value) => { | |
if (typeof value !== 'number'){ | |
throw 'not a number!' | |
} else { | |
return value | |
} | |
}; | |
const getAttempt = (input) => Either.try(() => fetchResult(input)); | |
const result = getAttempt(2) | |
.toMaybe() | |
.map(x => x * 4) | |
.map(x => x - 2) | |
.fold(e => console.warn('not yay'), | |
r => Maybe.of(r) | |
.map(x => x * 10) | |
.getOrElse('error')) | |
console.log('result: ', result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment