Module CCList.Assoc

type ('a, 'b) t = ('a * 'b) list
val get : eq:( 'a -> 'a -> bool ) -> 'a -> ( 'a, 'b ) t -> 'b option

get ~eq k alist returns Some v if the given key k is present into alist, or None if not present.

val get_exn : eq:( 'a -> 'a -> bool ) -> 'a -> ( 'a, 'b ) t -> 'b

get_exn ~eq k alist returns v if the element k is present into alist. Like get, but unsafe.

  • raises Not_found

    if the element is not present.

val set : eq:( 'a -> 'a -> bool ) -> 'a -> 'b -> ( 'a, 'b ) t -> ( 'a, 'b ) t

set ~eq k v alist adds the binding k, v into the list alist (erase it if already present).

val mem : ?eq:( 'a -> 'a -> bool ) -> 'a -> ( 'a, _ ) t -> bool

mem ?eq k alist returns true iff k is a key in alist.

  • since 0.16
val update : eq:( 'a -> 'a -> bool ) -> f:( 'b option -> 'b option ) -> 'a -> ( 'a, 'b ) t -> ( 'a, 'b ) t

update ~eq ~f k alist updates alist on the key k, by calling f (get k alist) and removing k if it returns None, mapping k to v' if it returns Some v'.

  • since 0.16
val remove : eq:( 'a -> 'a -> bool ) -> 'a -> ( 'a, 'b ) t -> ( 'a, 'b ) t

remove ~eq k alist returns the alist without the first pair with key k, if any.

  • since 0.17
val keys : ( 'a, 'b ) t -> 'a list

keys alist returns a list of all keys of alist.

  • since 3.8
val values : ( 'a, 'b ) t -> 'b list

values alist returns a list of all values of alist.

  • since 3.8
val map_values : ( 'b -> 'c ) -> ( 'a, 'b ) t -> ( 'a, 'c ) t

map_values f alist applies function f to all values of alist.

  • since 3.8