std.map

An ordered map list type

Types

type Map k a = 
    | Tip
    | Bin k a (Map k a) (Map k a)

Values

let eq : forall a a0 . [std.cmp.Eq a] -> [std.cmp.Eq a0] -> std.cmp.Eq (std.map.Map a a0)

Eq a defines equality (==) on a

let show : forall a a0 .
    [std.show.Show a] -> [std.show.Show a0] -> std.show.Show (std.map.Map a a0)

Show a represents a conversion function from a to a readable string.

let semigroup : forall a k . [std.cmp.Ord k] -> std.semigroup.Semigroup (std.map.Map k a)

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

let monoid : forall a k . [std.cmp.Ord k] -> std.monoid.Monoid (std.map.Map k a)

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

let functor : forall k . [std.cmp.Ord k] -> std.functor.Functor (std.map.Map k)

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

let foldable : forall k . [std.cmp.Ord k] -> std.foldable.Foldable (std.map.Map k)

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)

let traversable : forall k . [std.cmp.Ord k] -> std.traversable.Traversable (std.map.Map k)

let singleton k v : forall a a0 . a -> a0 -> std.map.Map a a0

Creates a map with a single entry.

let empty : forall a a0 . std.map.Map a a0

The empty map.

let find k m : forall a k . [std.cmp.Ord k] -> k -> std.map.Map k a -> std.types.Option a

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

let insert k v m : forall a k . [std.cmp.Ord k] -> k -> a -> std.map.Map k a -> std.map.Map k a

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 .
    [std.cmp.Ord k] -> (k -> a -> b) -> std.map.Map k a -> std.map.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 .
    [std.cmp.Ord k] -> (k -> a -> b -> b) -> b -> std.map.Map k a -> b

let foldl_with_key f z m : forall b a k .
    [std.cmp.Ord k] -> (a -> k -> b -> a) -> a -> std.map.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 .
    [std.cmp.Ord k]
        -> [std.applicative.Applicative t]
        -> (k -> a -> t b)
        -> std.map.Map k a
        -> t (std.map.Map k b)

Performs a traverse over the Map where the key gets passed to the function in addition to the value.

let to_list : forall a k .
    [std.cmp.Ord k] -> std.map.Map k a -> std.list.List { key : k, value : a }

let keys : forall a k . [std.cmp.Ord k] -> std.map.Map k a -> std.list.List k

Returns a list of all keys in the map.

let values : forall a k . [std.cmp.Ord k] -> std.map.Map k a -> std.list.List a

Returns a list of all values in the map.