Skip to content

Instantly share code, notes, and snippets.

@3v0k4
Last active December 21, 2019 00:08
Show Gist options
  • Select an option

  • Save 3v0k4/a02998f5fecbfe9eea015dbcc89499ea to your computer and use it in GitHub Desktop.

Select an option

Save 3v0k4/a02998f5fecbfe9eea015dbcc89499ea to your computer and use it in GitHub Desktop.
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