std.map
An ordered map list type
Types
Values
Eq a
defines equality (==) on a
Show a
represents a conversion function from a
to a readable string.
Semigroup a
represents an associative operation on a
.
This means the following laws must hold:
forall x . append x (append y z) == append (append x y) z
Monoid a
represents an semigroup an which has an identity. This means
the following additional laws must hold:
forall x . append x empty == x
forall x . append empty x == x
A Functor
represents an action on a parameterized type which does not
change the structure with the mapped type.
The following laws should hold:
map id == id
map (f << g) == map f << map g
Operations over a data structure that can be folded which means that a functions gets called on
each element to reduce the structure to a single value (Array
, List
and Map
are all Foldable
)
#[implicit]
let traversable : forall k . [Ord k] -> Traversable (Map k)
Creates a map with a single entry.
The empty map.
Searches the map m
for k
. Returns Some
with the element if it is found and otherwise None
.
let { ? } = import! std.effect
let map @ { ? } = import! std.map
let { (<>) } = import! std.semigroup
let { assert_eq, ? } = import! std.test
seq assert_eq (map.find "a" (map.singleton "a" 1)) (Some 1)
let my_map = map.singleton "a" 1 <> map.singleton "b" 2
seq assert_eq (map.find "b" my_map) (Some 2)
assert_eq (map.find "c" my_map) None
Inserts the value v
at the key k
in the map m
. If the key already exists in the map the current value gets replaced.
let map_with_key f m : forall b a k . [Ord k] -> (k -> a -> b) -> Map k a -> Map k b
Performs a map over the Map
where the key gets passed to the function in additon to the value.
let foldr_with_key f z m : forall b a k . [Ord k] -> (k -> a -> b -> b) -> b -> Map k a -> b
let foldl_with_key f z m : forall b a k . [Ord k] -> (a -> k -> b -> a) -> a -> Map k b -> a
Performs a fold over the Map
where the key gets passed to the function in addition to the value.
let traverse_with_key f m : forall b a t k .
[Ord k] -> [Applicative t] -> (k -> a -> t b) -> Map k a -> t (Map k b)
Performs a traverse over the Map
where the key gets passed to the function in addition to the value.
Returns a list of all keys in the map.
Returns a list of all values in the map.