add CCList.cons_maybe

This commit is contained in:
Simon Cruanes 2015-09-04 17:01:14 +02:00
parent 290ba2810a
commit 5069580a9d
2 changed files with 14 additions and 0 deletions

View file

@ -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 =

View file

@ -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