diff --git a/src/core/CCList.ml b/src/core/CCList.ml index a46f77be..b41ed2c3 100644 --- a/src/core/CCList.ml +++ b/src/core/CCList.ml @@ -382,17 +382,17 @@ let count f l = count (fun x -> x mod 2 = 0) [2; 6; 9; 4] = 3 *) -let counts p l = +let count_true_false p l = fold_left (fun (ok, ko) x -> if p x then (ok + 1, ko) else (ok, ko + 1) ) (0, 0) l (*$T - counts (fun x -> x mod 2 = 0) [] = (0, 0) - counts (fun x -> x mod 2 = 0) [0; 0; 2; 4] = (4, 0) - counts (fun x -> x mod 2 = 0) [1; 3; 5; 7] = (0, 4) - counts (fun x -> x mod 2 = 0) [2; 6; 9; 4] = (3, 1) + count_true_false (fun x -> x mod 2 = 0) [] = (0, 0) + count_true_false (fun x -> x mod 2 = 0) [0; 0; 2; 4] = (4, 0) + count_true_false (fun x -> x mod 2 = 0) [1; 3; 5; 7] = (0, 4) + count_true_false (fun x -> x mod 2 = 0) [2; 6; 9; 4] = (3, 1) *) let product f l1 l2 = diff --git a/src/core/CCList.mli b/src/core/CCList.mli index 2254a202..6b68d1c9 100644 --- a/src/core/CCList.mli +++ b/src/core/CCList.mli @@ -86,12 +86,12 @@ val fold_flat_map : ('acc -> 'a -> 'acc * 'b list) -> 'acc -> 'a list -> 'acc * @since 0.14 *) val count : ('a -> bool) -> 'a list -> int -(** [count p l] counts how many elements of [l] satisfy predicate [p]. +(** [count p l] count_true_false how many elements of [l] satisfy predicate [p]. @since 1.5 *) -val counts : ('a -> bool) -> 'a list -> int * int -(** [let ok_count, ko_count = counts p l in ...] - counts how many elements of [l] satisfy (resp. violate) predicate [p]. +val count_true_false : ('a -> bool) -> 'a list -> int * int +(** [let ok_count, ko_count = count_true_false p l in ...] + count_true_false how many elements of [l] satisfy (resp. violate) predicate [p]. @since NEXT_RELEASE *) val init : int -> (int -> 'a) -> 'a t diff --git a/src/core/CCListLabels.mli b/src/core/CCListLabels.mli index 1b8c8e38..c3372361 100644 --- a/src/core/CCListLabels.mli +++ b/src/core/CCListLabels.mli @@ -86,7 +86,7 @@ val fold_flat_map : f:('acc -> 'a -> 'acc * 'b list) -> init:'acc -> 'a list -> val count : f:('a -> bool) -> 'a list -> int (** @since 2.2 *) -val counts : f:('a -> bool) -> 'a list -> int * int +val count_true_false : f:('a -> bool) -> 'a list -> int * int (** @since NEXT_RELEASE *) val init : int -> f:(int -> 'a) -> 'a t