diff --git a/src/core/CCList.ml b/src/core/CCList.ml index d2704c10..8127db8f 100644 --- a/src/core/CCList.ml +++ b/src/core/CCList.ml @@ -82,6 +82,15 @@ let (@) = append (1-- 10_000) @ (10_001 -- 20_000) = 1 -- 20_000 *) +let cons_maybe o l = match o with + | Some x -> x :: l + | None -> l + +(*$T + cons_maybe (Some 1) [2;3] = [1;2;3] + cons_maybe None [2;3] = [2;3] +*) + let direct_depth_filter_ = 10_000 let filter p l = diff --git a/src/core/CCList.mli b/src/core/CCList.mli index 3cd47a94..23670121 100644 --- a/src/core/CCList.mli +++ b/src/core/CCList.mli @@ -48,6 +48,11 @@ val cons : 'a -> 'a t -> 'a t val append : 'a t -> 'a t -> 'a t (** Safe version of append *) +val cons_maybe : 'a option -> 'a t -> 'a t +(** [cons_maybe (Some x) l] is [x :: l] + [cons_maybe None l] is [l] + @since NEXT_RELEASE *) + val (@) : 'a t -> 'a t -> 'a t val filter : ('a -> bool) -> 'a t -> 'a t