mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 03:05:28 -05:00
feat(CCList): add cons_when
This commit is contained in:
parent
570e3f8d67
commit
4ff1853222
2 changed files with 11 additions and 0 deletions
|
|
@ -151,6 +151,12 @@ let cons_maybe o l =
|
|||
| Some x -> x :: l
|
||||
| None -> l
|
||||
|
||||
let cons_when b x l =
|
||||
if b then
|
||||
x :: l
|
||||
else
|
||||
l
|
||||
|
||||
[@@@iflt 4.14]
|
||||
|
||||
let direct_depth_filter_ = 10_000
|
||||
|
|
|
|||
|
|
@ -25,6 +25,11 @@ val cons_maybe : 'a option -> 'a t -> 'a t
|
|||
[cons_maybe None l] is [l].
|
||||
@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
|
||||
(** [cons' l x] is the same as [x :: l]. This is convenient for fold
|
||||
functions such as {!List.fold_left} or {!Array.fold_left}.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue