Skip to content

Instantly share code, notes, and snippets.

@victorvoid

victorvoid/composability-example04.js Secret

Last active Aug 20, 2018
Embed
What would you like to do?
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
You can’t perform that action at this time.