/Prelude-v16.0.0/List/map

Copy path to clipboard

Examples

map Natural Bool Natural/even [ 2, 3, 5 ] ≡ [ True, False, False ]
map Natural Bool Natural/even ([] : List Natural) ≡ ([] : List Bool)

Source

{-
Transform a list by applying a function to each element
-}
let map
: ∀(a : Type) → ∀(b : Type) → (a → b) → List a → List b
= λ(a : Type)
→ λ(b : Type)
→ λ(f : ab)
→ λ(xs : List a)
→ List/build
b
( λ(list : Type)
→ λ(cons : blistlist)
→ List/fold a xs list (λ(x : a) → cons (f x))
)

let example0 =
assert
: map Natural Bool Natural/even [ 2, 3, 5 ] ≡ [ True, False, False ]

let example1 =
assert
: map Natural Bool Natural/even ([] : List Natural) ≡ ([] : List Bool)

in map