Skip to content

Instantly share code, notes, and snippets.

@JoelQ
Created May 30, 2018
Embed
What would you like to do?
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