Last active
December 9, 2015 15:12
-
-
Save dasch/d6aa392553ed3b5e3b33 to your computer and use it in GitHub Desktop.
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
with Task.andThen do | |
issues = Http.get "/issues.json" | |
milestones = Http.get "milestones.json" | |
in | |
assignMilestones (issues, milestones) | |
-- This would desugar to: | |
Task.andThen | |
(Http.get "/issues.json") | |
(\issues -> | |
Task.andThen | |
(Http.get "milestones.json") | |
(\milestones -> | |
assignMilestones (issues, milestones))) |
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
type Person = Person { name : String, age : Int } | |
with Maybe.andThen do | |
name = Dict.get names id | |
age = Dict.get ages id | |
in | |
Person { name = name, age = age } | |
-- desugar | |
Maybe.andThen | |
(Dict.get names id) | |
(\name -> | |
Maybe.andThen | |
(Dict.get ages id) | |
(\age -> | |
Person { name = name, age = age })) | |
-- even better | |
body : (Maybe a -> Maybe b) -> Person | |
body = do | |
name = Dict.get names id | |
age = Dict.get ages id | |
in | |
Person { name = name, age = age } | |
with : (m a -> m b) -> ((m a -> m b) -> c) -> c | |
with f body = body f | |
withMaybe : ((Maybe a -> Maybe b) -> c) -> c | |
withMaybe = with Maybe.andThen | |
result = withMaybe body |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment