Created
April 9, 2019 00:08
-
-
Save mlms13/4cf934e9e3b4c4af3d9e14977faec7e7 to your computer and use it in GitHub Desktop.
I don't know anything about PPXs, and I'm not even quite a do-notation pro, but I'd really like something like this in Reason
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
[%do Future] | |
do { | |
user <- getUser("some_user_id") | |
orders = user.orders | |
firstOrderId <- orders |> List.head |> Future.fromOption | |
order <- getOrder(firstOrderId) | |
pure(user.firstName ++ " ordered a " ++ order.productName) | |
}; | |
Future.( | |
getUser("some_user_id") | |
|> flatMap(user => { | |
let orders = user.orders; | |
orders |> List.head |> fromOption |> flatMap(firstOrderId => { | |
getOrder(firstOrderId) |> Future.flatMap(order => { | |
pure(user.firstName ++ "ordered a " ++ order.productName) | |
}) | |
}) | |
}) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment