Skip to content

Instantly share code, notes, and snippets.

@mlms13
Created February 24, 2019 18:01
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 mlms13/85198a48ddea15a495ca39615cba426d to your computer and use it in GitHub Desktop.
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
/**
* 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