Last active
December 21, 2019 00:08
-
-
Save 3v0k4/a02998f5fecbfe9eea015dbcc89499ea 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 Result = require('folktale/result') | |
| const first = xs => Result.fromNullable(xs[0]) | |
| const parse = s => Result.try(() => JSON.parse(s)) | |
| const upper = s => s.toUpperCase() | |
| const shout = s => s.concat('!') | |
| const format = s => Result.Ok(s).map(upper).map(shout) | |
| const functional = s => Result.Ok(s).chain(parse).chain(first).chain(format) | |
| functional('["hello", "world"]') | |
| // Resull.ok(HELLO!) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment