diff --git a/src/core/CCList.ml b/src/core/CCList.ml index e8b5be45..87c7fefc 100644 --- a/src/core/CCList.ml +++ b/src/core/CCList.ml @@ -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 diff --git a/src/core/CCList.mli b/src/core/CCList.mli index 865dca79..4f54dbb3 100644 --- a/src/core/CCList.mli +++ b/src/core/CCList.mli @@ -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}.