Skip to content

Instantly share code, notes, and snippets.

@laduke
Created August 17, 2017 16:52
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 laduke/fce2732b37a012a4c8f3df57e8ef15cc to your computer and use it in GitHub Desktop.
Save laduke/fce2732b37a012a4c8f3df57e8ef15cc to your computer and use it in GitHub Desktop.
Maybe to Future
// Courtesy https://gitter.im/sanctuary-js/sanctuary
// maybeToFuture :: a -> Maybe b -> Future a b
const maybeToFuture = S.curry2((x, maybe) =>
S.maybe(Future.reject(x), Future.of, maybe)
);
// Collapse a `Future String (Maybe Integer)` into a `Future String Integer`.
S.chain(maybeToFuture('parseInt: "XXX" does not represent an integer'),
Future.of(S.Nothing));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment