Skip to content

Instantly share code, notes, and snippets.

@dasch
Last active December 9, 2015 15:12
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 dasch/d6aa392553ed3b5e3b33 to your computer and use it in GitHub Desktop.
Save dasch/d6aa392553ed3b5e3b33 to your computer and use it in GitHub Desktop.
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)))
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