Map

=

defn

(λ [(Ref (Map a b)), (Ref (Map a b))] Bool)

                    (= m1 m2)
                

all?

defn

(λ [(Ref (λ [&a, &b] Bool)), (Ref (Map a b))] Bool)

                    (all? pred m)
                

Do all key-value pairs pass the given predicate (of two arguments)?

buckets

instantiate

(λ [(Ref (Map a b))] (Ref (Array (Bucket a b))))

gets the buckets property of a Map.

contains?

defn

(λ [(Ref (Map a b)), &a] Bool)

                    (contains? m k)
                

Check whether the map m contains the key k.

copy

template

(λ [(Ref (Map a b))] (Map a b))

copies the Map.

create

defn

(λ [] (Map a b))

                    (create)
                

Create an empty map.

create-with-len

defn

(λ [Int] (Map a b))

                    (create-with-len len)
                

Create an empty map with a given number of buckets. High numbers reduce the possibility of hash collisions while increasing the memory footprint.

delete

template

(λ [(Map a b)] ())

deletes a Map. Should usually not be called manually.

empty?

defn

(λ [a] Bool)

                    (empty? m)
                

Check whether the map m is empty.

endo-map

defn

(λ [(Ref (λ [&a, &b] b)), (Map a b)] (Map a b))

                    (endo-map f m)
                

Transform values of the given map in place. f gets two arguments, key and value, and should return new value

for-each

defn

(λ [(Ref (Map a b)), (Ref (λ [&a, &b] ()))] ())

                    (for-each m f)
                

Execute the binary function f for all keys and values in the map m.

from-array

defn

(λ [(Ref (Array (Pair a b)))] (Map a b))

                    (from-array a)
                

Create a map from the array a containing key-value pairs.

get

defn

(λ [(Ref (Map a b)), &a] b)

                    (get m k)
                

Get the value for the key k from map m. If it isn’t found, a zero element for the value type is returned.

get-maybe

defn

(λ [(Ref (Map a b)), &a] (Maybe b))

                    (get-maybe m k)
                

Get the value for the key k from map m. It returns a Maybe type, meaning that if nothing is found, Nothing is returned.

get-with-default

defn

(λ [(Ref (Map a b)), &a, &b] b)

                    (get-with-default m k default-value)
                

Get the value for the key k from map m. If it isn’t found, the default is returned.

init

template

(λ [Int, (Array (Bucket a b))] (Map a b))

creates a Map.

keys

defn

(λ [(Ref (Map a b))] (Array a))

                    (keys m)
                

Return an array of the keys of the map. Order corresponds to order of (vals m)

kv-reduce

defn

(λ [(Ref (λ [a, &b, &c] a)), a, (Ref (Map b c))] a)

                    (kv-reduce f init m)
                

Reduce a map with a function of three arguments: state, key and value. Reduction order is not guaranteed.

length

defn

(λ [(Ref (Map a b))] Int)

                    (length m)
                

Get the length of the map m.

n-buckets

instantiate

(λ [(Ref (Map a b))] &Int)

gets the n-buckets property of a Map.

prn

template

(λ [(Ref (Map a b))] String)

converts a Map to a string.

put

defn

(λ [(Map a b), &a, &b] (Map a b))

                    (put m k v)
                

Put a a value v into map m, using the key k.

put!

defn

(λ [(Ref (Map a b)), &a, &b] ())

                    (put! m k v)
                

Put a a value v into map m, using the key k, in place.

remove

defn

(λ [(Map a b), &a] (Map a b))

                    (remove m k)
                

Remove the value under the key k from the map m.

reverse

defn

(λ [(Ref (Map a b))] (Map b a))

                    (reverse m)
                

reverses they keys and values in a given map m.

set-buckets

template

(λ [(Map a b), (Array (Bucket a b))] (Map a b))

sets the buckets property of a Map.

set-buckets!

instantiate

(λ [(Ref (Map a b)), (Array (Bucket a b))] ())

sets the buckets property of a Map in place.

set-n-buckets

instantiate

(λ [(Map a b), Int] (Map a b))

sets the n-buckets property of a Map.

set-n-buckets!

instantiate

(λ [(Ref (Map a b)), Int] ())

sets the n-buckets property of a Map in place.

str

defn

(λ [(Ref (Map a b))] String)

                    (str m)
                

converts a Map to a string.

to-array

defn

(λ [(Ref (Map a b))] (Array (Pair a b)))

                    (to-array m)
                

Convert Map to Array of Pairs

update

defn

(λ [(Map a b), &a, (Ref (λ [b] b))] (Map a b))

                    (update m k f)
                

Update value at key k in map with function f, if it exists.

update-buckets

instantiate

(λ [(Map a b), (Ref (λ [(Array (Bucket a b))] (Array (Bucket a b))))] (Map a b))

updates the buckets property of a Map using a function f.

update-n-buckets

instantiate

(λ [(Map a b), (Ref (λ [Int] Int))] (Map a b))

updates the n-buckets property of a Map using a function f.

update-with-default

defn

(λ [(Map a b), &a, (Ref (λ [b] b)), b] (Map a b))

                    (update-with-default m k f v)
                

Update value at key k in map with function f. If k doesn't exist in map, set k to (f v).

vals

defn

(λ [(Ref (Map a b))] (Array b))

                    (vals m)
                

Return an array of the values of the map. Order corresponds to order of (keys m)