Created
October 21, 2017 03:47
-
-
Save laduke/49c10f362145c60dccdaa5e5010e4dcf to your computer and use it in GitHub Desktop.
This file contains 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
// maybeToFuture :: a -> Maybe b -> Future a b | |
const maybeToFuture = S.curry2((x, maybe) => | |
S.maybe(Future.reject(x), Future.of, maybe) | |
); | |
//also | |
/* | |
Aldwin Vlasblom @Avaq Aug 14 05:12 | |
I generally have two strategies for dealing with a Future(Just(x)): | |
Using maybeToFuture. @davidchambers just posted an implementation. I use this when Nothing represents an actual error in the code (one that can only be recovered from by my generic error recovery procedure, which usually reports the error and crashes the process). | |
Using fromMaybe. Like you suggested, but limited to cases where the Nothing can be turned into a reasonable fallback value. | |
In the first case, I usually do the conversion as early as possible. In the second, I usually do the conversion as late as possible to avoid doing unnecessary computations on the default value (you can just pre-compute it and insert it later in the pipeline). | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment