Module Js.MapSource

Provides bindings for ES6 Map

Mutable, insertion-ordered map matching JS Map semantics: iteration order is insertion order, re-setting an existing key keeps its position, and deleting then re-adding a key moves it to the end.

Divergences from JavaScript:

Sourcetype ('k, 'v) t

The Map type

Sourceval make : unit -> ('k, 'v) t

make () creates a new empty map.

Sourceval fromArray : ('k * 'v) array -> ('k, 'v) t

fromArray entries creates a map from an array of (key, value) pairs. Like JS new Map(entries), a duplicated key keeps the position of its first occurrence but the value of its last one.

Sourceval toArray : ('k, 'v) t -> ('k * 'v) array

toArray map returns the (key, value) pairs in insertion order, like JS Array.from(map).

Sourceval size : ('k, 'v) t -> int

size map returns the number of entries in map.

Sourceval has : key:'k -> ('k, 'v) t -> bool

has ~key map returns whether key is present in map.

Sourceval get : key:'k -> ('k, 'v) t -> 'v option

get ~key map returns Some value if key is present, None otherwise.

Sourceval set : key:'k -> value:'v -> ('k, 'v) t -> ('k, 'v) t

set ~key ~value map sets key to value in map (mutating it) and returns map for chaining.

Sourceval clear : ('k, 'v) t -> unit

clear map removes all entries from map.

Sourceval delete : key:'k -> ('k, 'v) t -> bool

delete ~key map removes key from map; returns whether the key was present.

Sourceval forEach : f:('v -> 'k -> ('k, 'v) t -> unit) -> ('k, 'v) t -> unit

forEach ~f map calls f value key map for each entry in insertion order, like JS Map.prototype.forEach.

Sourceval keys : ('k, 'v) t -> 'k Js__.Js_iterator.t

keys map returns an iterator over the keys in insertion order.

Sourceval values : ('k, 'v) t -> 'v Js__.Js_iterator.t

values map returns an iterator over the values in insertion order.

Sourceval entries : ('k, 'v) t -> ('k * 'v) Js__.Js_iterator.t

entries map returns an iterator over the (key, value) pairs in insertion order.