Dictionary_immutable.S1
val is_empty : _ t -> bool
Whether the dictionary is empty.
val length : _ t -> int
How many key/value pairs the dictionary contains.
val data : 'data t -> 'data list
All values in the dictionary, in the same order as to_alist
.
val to_sequence : 'data t -> (key * 'data) Sequence.t
Like to_alist
. Produces a sequence.
Produces the current value, or absence thereof, for a given key.
Adds a key/value pair for a key the dictionary does not contain, or reports a duplicate.
Adds or replaces a key/value pair in the dictionary.
Adds, replaces, or removes the value for a given key, depending on its current value or lack thereof.
Adds or replaces the value for a given key, depending on its current value or lack thereof.
Adds data
to the existing key/value pair for key
. Interprets a missing key as having an empty list.
Removes one element from the existing key/value pair for key
. Removes the key entirely if the new list is empty.
Produces the list associated with the corresponding key. Interprets a missing key as having an empty list.
Combines every value in the dictionary.
val fold_until :
'data t ->
init:'acc ->
f:
(key:key ->
data:'data ->
'acc ->
('acc, 'final) Container.Continue_or_stop.t) ->
finish:('acc -> 'final) ->
'final
Like fold
. May stop before completing the iteration.
val for_all : 'data t -> f:('data -> bool) -> bool
Whether every value satisfies f
.
Like for_all
. The predicate may also depend on the associated key.
val exists : 'data t -> f:('data -> bool) -> bool
Whether at least one value satisfies f
.
Like exists
. The predicate may also depend on the associated key.
val count : 'data t -> f:('data -> bool) -> int
How many values satisfy f
.
Like count
. The predicate may also depend on the associated key.
val sum :
(module Container.Summable with type t = 'a) ->
'data t ->
f:('data -> 'a) ->
'a
Sum up f data
for all data in the dictionary.
val sumi :
(module Container.Summable with type t = 'a) ->
'data t ->
f:(key:'key -> data:'data -> 'a) ->
'a
Like sum
. The function may also depend on the associated key.
Produces the key/value pair with the smallest key if non-empty.
Produces the key/value pair with the largest key if non-empty.
val iter : 'data t -> f:('data -> unit) -> unit
Calls f
for every value.
Like map
. The transformation may also depend on the associated key.
Produces only those key/value pairs whose key satisfies f
.
Produces only those key/value pairs whose value satisfies f
.
Produces only those key/value pairs which satisfy f
.
Produces key/value pairs for which f
produces Some
.
Like filter_map
. The new value may also depend on the associated key.
Splits one dictionary into two. The first contains key/value pairs for which the value satisfies f
. The second contains the remainder.
Like partition_tf
. The predicate may also depend on the associated key.
Splits one dictionary into two, corresponding respectively to First _
and Second _
results from f
.
val partition_mapi :
'data1 t ->
f:(key:key -> data:'data1 -> ('data2, 'data3) Either.t) ->
'data2 t * 'data3 t
Like partition_map
. The split may also depend on the associated key.
val combine_errors : 'data Or_error.t t -> 'data t Or_error.t
Produces an error combining all error messages from key/value pairs, or a dictionary of all Ok
values if none are Error
.
Splits the fst
and snd
components of values associated with keys into separate dictionaries.
val merge :
'data1 t ->
'data2 t ->
f:
(key:key ->
[ `Left of 'data1 | `Right of 'data2 | `Both of 'data1 * 'data2 ] ->
'data3 option) ->
'data3 t
Merges two dictionaries by fully traversing both. Not suitable for efficiently merging lists of dictionaries. See merge_disjoint_exn
and merge_skewed
instead.
Merges two dictionaries with the same type of data and disjoint sets of keys. Raises if any keys overlap.
Merges two dictionaries by traversing only the smaller of the two. Adds key/value pairs missing from the larger dictionary, and combine
s duplicate values.
val symmetric_diff :
'data t ->
'data t ->
data_equal:('data -> 'data -> bool) ->
(key * [ `Left of 'data | `Right of 'data | `Unequal of 'data * 'data ])
Sequence.t
Computes a sequence of differences between two dictionaries.
val fold_symmetric_diff :
'data t ->
'data t ->
data_equal:('data -> 'data -> bool) ->
init:'acc ->
f:
('acc ->
(key * [ `Left of 'data | `Right of 'data | `Unequal of 'data * 'data ]) ->
'acc) ->
'acc
Folds over the result of symmetric_diff
. May be more performant.
val empty : 'data t
The empty dictionary.
Dictionary containing the given key/value pairs. Fails if there are duplicate keys.
val of_alist_or_error : (key * 'data) list -> 'data t Or_error.t
Like of_alist
. Returns a Result.t
.
Produces a dictionary mapping each key to a list of associated values.
Produces a dictionary using each key/value pair. Combines all values for a given key with init
using f
.
Produces a dictionary using each key/value pair. Combines multiple values for a given key using f
.
val of_sequence :
(key * 'data) Sequence.t ->
[ `Ok of 'data t | `Duplicate_key of key ]
Like of_alist
. Consumes a sequence.
val of_sequence_or_error : (key * 'data) Sequence.t -> 'data t Or_error.t
Like of_alist_or_error
. Consumes a sequence.
val of_sequence_exn : (key * 'data) Sequence.t -> 'data t
Like of_alist_exn
. Consumes a sequence.
val of_sequence_multi : (key * 'data) Sequence.t -> 'data list t
Like of_alist_multi
. Consumes a sequence.
val of_sequence_fold :
(key * 'data) Sequence.t ->
init:'c ->
f:('c -> 'data -> 'c) ->
'c t
Like of_alist_fold
. Consumes a sequence.
val of_sequence_reduce :
(key * 'data) Sequence.t ->
f:('data -> 'data -> 'data) ->
'data t
Like of_alist_reduce
. Consumes a sequence.
val of_list_with_key :
'data list ->
get_key:('data -> key) ->
[ `Ok of 'data t | `Duplicate_key of key ]
Like of_alist
. Consume values for which keys can be computed.
val of_list_with_key_or_error :
'data list ->
get_key:('data -> key) ->
'data t Or_error.t
Like of_alist_or_error
. Consume values for which keys can be computed.
Like of_alist_exn
. Consume values for which keys can be computed.
Like of_alist_multi
. Consume values for which keys can be computed.