Skip to content

Instantly share code, notes, and snippets.

@Nauthiz-Jera
Last active October 30, 2018 15:39
Show Gist options
  • Save Nauthiz-Jera/28d959700b00269d769679339b4f7579 to your computer and use it in GitHub Desktop.
Save Nauthiz-Jera/28d959700b00269d769679339b4f7579 to your computer and use it in GitHub Desktop.
Playing with Folktale
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