Skip to content

Instantly share code, notes, and snippets.

@JoelQ
Created May 30, 2018 18:08
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 JoelQ/9a3a33ef77f4e565e6f92627b3001743 to your computer and use it in GitHub Desktop.
Save JoelQ/9a3a33ef77f4e565e6f92627b3001743 to your computer and use it in GitHub Desktop.
A look at mapN functions in Elm. The `map0` function is just the constructor function! Haskell folks would call this pure/return.
-- Maybe
map2 f v1 v2 = Just f |> andMap v1 |> andMap v2
map f v1 = Just f |> andMap v1
map0 f = Just f
-- List
map2 f v1 v2 = singleton f |> andMap v1 |> andMap v2
map f v1 = singleton f |> andMap v1
map0 f = singleton f
-- Json.Decode.Decoder
map2 f v1 v2 = succeed f |> andMap v1 |> andMap v2
map f v1 = succeed f |> andMap v1
map0 f = succeed f
-- Random.Generator
map2 f v1 v2 = constant f |> andMap v1 |> andMap v2
map f v1 = constant f |> andMap v1
map0 f = constant f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment