Skip to content

Instantly share code, notes, and snippets.

@victorvoid
Last active August 20, 2018 19:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save victorvoid/0bdf8e663cf1813a64494b5e880cb010 to your computer and use it in GitHub Desktop.
Save victorvoid/0bdf8e663cf1813a64494b5e880cb010 to your computer and use it in GitHub Desktop.
const Right = x => ({
map: f => Right(f(x)),
chain: f => f(x),
fold: (f, g) => g(x)
})
const Left = x => ({
map: f => Left(x),
chain: f => Left(x),
fold: (f, g) => f(x)
})
const getPackages = user =>
(user.premium ? Right(user) : Left('not premium'))
.map(u => u.preferences)
.fold(() => defaultsPackages, props => loadPackages(props))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment