feat(CCList): Add keys, values, and map_values

This commit is contained in:
Daniil Baturin 2022-06-01 15:38:22 +03:00
parent 70703b3512
commit 0075378f29
3 changed files with 31 additions and 0 deletions

View file

@ -1814,6 +1814,12 @@ module Assoc = struct
[1,"1"; 2,"2"] \
(Assoc.remove ~eq:CCInt.equal 3 [1,"1"; 2,"2"] |> lsort)
*)
let keys l = map (fun (k, _) -> k) l
let values l = map (fun (_, v) -> v) l
let map_values f l = map (fun (k, v) -> (k, f v)) l
end
let assoc = Assoc.get_exn

View file

@ -747,6 +747,18 @@ module Assoc : sig
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 *)
end
val assoc : eq:('a -> 'a -> bool) -> 'a -> ('a * 'b) t -> 'b

View file

@ -711,6 +711,19 @@ module Assoc : sig
val remove : eq:(('a->'a->bool) [@keep_label]) -> '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 *)
end
val assoc : eq:(('a -> 'a -> bool) [@keep_label]) -> 'a -> ('a * 'b) t -> 'b