std.map

An ordered map list type

Types

#[derive(Eq, Show)]
type Map k a = 
    | Tip
    | Bin k a (Map k a) (Map k a)

Values

#[implicit]
let eq : forall a a0 . [Eq a] -> [Eq a0] -> Eq (Map a a0)

Eq a defines equality (==) on a

#[implicit]
let show : forall a a0 . [Show a] -> [Show a0] -> Show (Map a a0)

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

#[implicit]
let semigroup : forall a k . [Ord k] -> Semigroup (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

#[implicit]
let monoid : forall a k . [Ord k] -> Monoid (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

#[implicit]
let functor : forall k . [Ord k] -> Functor (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

#[implicit]
let foldable : forall k . [Ord k] -> Foldable (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)

#[implicit]
let traversable : forall k . [Ord k] -> Traversable (Map k)

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

Creates a map with a single entry.

#[derive(Eq, Show)]
let empty : forall a a0 . Map a a0

The empty map.

let find k m : forall a k . [Ord k] -> k -> Map k a -> 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 . [Ord k] -> k -> a -> Map k a -> 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 . [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.

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

let keys : forall a k . [Ord k] -> Map k a -> List k

Returns a list of all keys in the map.

let values : forall a k . [Ord k] -> Map k a -> List a

Returns a list of all values in the map.