Created
February 24, 2019 18:01
-
-
Save mlms13/85198a48ddea15a495ca39615cba426d to your computer and use it in GitHub Desktop.
t-first and t-last approach when working with nested data structures in Reason
This file contains hidden or 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
/** | |
* t-first and t-last examples when working with `Future.t(Result.t('a, 'e))` | |
**/ | |
// `Future` and `Result` are both t-last | |
getJSON("some/url") | |
|> Future.map(Result.flatMap(decodeUser)) | |
|> Future.map(Result.mapWithDefault(DataFailed, v => ShowData(v))) | |
|> Future.tap(send); | |
// t-first, as the API currently exists, with extra arguments named | |
// only so they can be passed into other functions | |
getJSON("some/url") | |
->Future.map(res => Result.flatMap(res, decodeUser)) | |
->Future.map(res => Result.mapWithDefault(res, DataFailed, v => ShowData(v))) | |
->Future.tap(send); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment