Bytes.Map

A BytesMap is a dictionnary mapping unique keys to values, where all keys are byte strings.

Insert, remove, and query operations all take O(log n) time.

BytesMaps

type BytesMap k v

Dictionary mapping [Bytes] keys to values.

Build

Create an empty BytesMap.

singleton : Bytes k -> v -> BytesMap k v

Create a BytesMap with one key-value pair.

insert : Bytes k -> v -> BytesMap k v -> BytesMap k v

Insert a key-value pair into a BytesMap. Replaces value when there is a collision.

update : Bytes k -> (Maybe v -> Maybe v) -> BytesMap k v -> BytesMap k v

Update the value of a BytesMap for a specific key with a given function.

remove : Bytes k -> BytesMap k v -> BytesMap k v

Remove a key-value pair from a BytesMap. If the key is not found, no changes are made.

Query

isEmpty : BytesMap k v -> Bool

Determine if a BytesMap is empty.

member : Bytes k -> BytesMap k v -> Bool

Determine if a key is in a BytesMap.

get : Bytes k -> BytesMap k v -> Maybe v

Get the value associated with a key. If the key is not found, return Nothing. This is useful when you are not sure if a key will be in the BytesMap

size : BytesMap k v -> Int

Determine the number of key-value pairs in the BytesMap.

Lists

keys : BytesMap k v -> List (Bytes k)

Get all of the keys in a BytesMap, sorted from lowest to highest.

values : BytesMap k v -> List v

Get all of the values in a dictionary, in the order of their keys.

toList : BytesMap k v -> List ( Bytes k, v )

Convert a BytesMap into an association list of key-value pairs, sorted by keys.

fromList : List ( Bytes k, v ) -> BytesMap k v

Convert an association list into a BytesMap.

Transform

map : (a -> b) -> BytesMap k a -> BytesMap k b

Apply a function to all values in a BytesMap.

mapWithKeys : (Bytes k -> a -> b) -> BytesMap k a -> BytesMap k b

Apply a function to all keys and values in a BytesMap.

foldl : (v -> result -> result) -> result -> BytesMap k v -> result

Fold over the values in a BytesMap from lowest key to highest key.

foldlWithKeys : (Bytes k -> v -> result -> result) -> result -> BytesMap k v -> result

Fold over the key-value pairs in a BytesMap from lowest key to highest key.

foldr : (v -> result -> result) -> result -> BytesMap k v -> result

Fold over the values in a BytesMap from highest key to lowest key.

foldrWithKeys : (Bytes k -> v -> result -> result) -> result -> BytesMap k v -> result

Fold over the key-value pairs in a BytesMap from highest key to lowest key.

filter : (v -> Bool) -> BytesMap k v -> BytesMap k v

Keep only the values that pass the given test.

filterWithKeys : (Bytes k -> v -> Bool) -> BytesMap k v -> BytesMap k v

Keep only the key-value pairs that pass the given test.

Combine

union : BytesMap k v -> BytesMap k v -> BytesMap k v

Combine two BytesMap. If there is a collision, preference is given to the first BytesMap.

intersect : BytesMap k v -> BytesMap k v -> BytesMap k v

Keep a key-value pair when its key appears in the second BytesMap. Preference is given to values in the first BytesMap.

diff : BytesMap k v -> BytesMap k v -> BytesMap k v

Keep a key-value pair when its key does not appear in the second BytesMap.

(Bytes k -> a -> result -> result)
-> (Bytes k -> a -> b -> result -> result)
-> (Bytes k -> b -> result -> result)
-> BytesMap k a
-> BytesMap k b
-> result
-> result

The most general way of combining two BytesMap. You provide three accumulators for when a given key appears:

  • Only in the left BytesMap.
  • In both BytesMap.
  • Only in the right BytesMap.

You then traverse all the keys from lowest to highest, building up whatever you want.

Encode / Decode

toCbor : (v -> Encoder) -> BytesMap k v -> Encoder

Cbor encoder.

fromCbor : Decoder v -> Decoder (BytesMap k v)

CBOR decoder.