feat(CCList): add cons_when

This commit is contained in:
Nicola Mometto 2024-04-19 09:55:03 +01:00 committed by Simon Cruanes
parent 570e3f8d67
commit 4ff1853222
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
2 changed files with 11 additions and 0 deletions

View file

@ -151,6 +151,12 @@ let cons_maybe o l =
| Some x -> x :: l | Some x -> x :: l
| None -> l | None -> l
let cons_when b x l =
if b then
x :: l
else
l
[@@@iflt 4.14] [@@@iflt 4.14]
let direct_depth_filter_ = 10_000 let direct_depth_filter_ = 10_000

View file

@ -25,6 +25,11 @@ val cons_maybe : 'a option -> 'a t -> 'a t
[cons_maybe None l] is [l]. [cons_maybe None l] is [l].
@since 0.13 *) @since 0.13 *)
val cons_when : bool -> 'a -> 'a t -> 'a t
(** [cons_when true x l] is [x :: l].
[cons_when false x l] is [l].
@since NEXT_RELEASE *)
val cons' : 'a t -> 'a -> 'a t val cons' : 'a t -> 'a -> 'a t
(** [cons' l x] is the same as [x :: l]. This is convenient for fold (** [cons' l x] is the same as [x :: l]. This is convenient for fold
functions such as {!List.fold_left} or {!Array.fold_left}. functions such as {!List.fold_left} or {!Array.fold_left}.