std.map

An ordered map list type

Types

type Map k a = 
    | Tip
    | Bin k a (std.map.Map k a) (std.map.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 a0 . [std.cmp.Ord a] -> std.semigroup.Semigroup (std.map.Map a a0)

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 a0 . [std.cmp.Ord a] -> std.monoid.Monoid (std.map.Map a a0)

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

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

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

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 a0 . [std.cmp.Ord a] -> a -> std.map.Map a a0 -> std.types.Option a0

Searches the map m for k. Returns Some with the element if it is found and otherwise None.

let map @ { ? } = import! std.map
let { (<>) } = import! std.semigroup
let { assert } = import! std.test

assert (map.find "a" (map.singleton "a" 1) == Some 1)

let my_map = map.singleton "a" 1 <> map.singleton "b" 2
assert (map.find "b" my_map == Some 2)
assert (map.find "c" my_map == None)

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

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

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

let foldl_with_key f z m : forall a a0 a1 .
    [std.cmp.Ord a] -> (a0 -> a -> a1 -> a0) -> a0 -> std.map.Map a a1 -> a0

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 a a0 a1 a2 .
    [std.cmp.Ord a]
        -> [std.applicative.Applicative a0]
        -> (a -> a1 -> a0 a2)
        -> std.map.Map a a1
        -> a0 (std.map.Map a a2)

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

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

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

Returns a list of all keys in the map.

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

Returns a list of all values in the map.