dhall-nix-lib/Map/map.dhall

49 lines
1.2 KiB
Text

--| Transform a `Map` by applying a function to each value
let Map = ./Type.dhall
let Entry = ./Entry.dhall
let List/map = ../List/map.dhall
let map
: ∀(k : Type) → ∀(a : Type) → ∀(b : Type) → (a → b) → Map k a → Map k b
= λ(k : Type) →
λ(a : Type) →
λ(b : Type) →
λ(f : a → b) →
λ(m : Map k a) →
List/map
(Entry k a)
(Entry k b)
( λ(before : Entry k a) →
{ mapKey = before.mapKey, mapValue = f before.mapValue }
)
m
let example0 =
assert
: map
Text
Natural
Bool
Natural/even
[ { mapKey = "A", mapValue = 2 }
, { mapKey = "B", mapValue = 3 }
, { mapKey = "C", mapValue = 5 }
]
≡ [ { mapKey = "A", mapValue = True }
, { mapKey = "B", mapValue = False }
, { mapKey = "C", mapValue = False }
]
let example1 =
assert
: map
Text
Natural
Bool
Natural/even
([] : List { mapKey : Text, mapValue : Natural })
≡ ([] : List { mapKey : Text, mapValue : Bool })
in map