diff --git a/src/core/CCList.ml b/src/core/CCList.ml index 0aef95d4..f46e06a8 100644 --- a/src/core/CCList.ml +++ b/src/core/CCList.ml @@ -148,6 +148,12 @@ let (@) = append (1-- 10_000) @ (10_001 -- 20_000) = 1 -- 20_000 *) +let[@inline] cons' l x = x::l + +(*$Q + Q.(small_list int)(fun l -> List.rev l = List.fold_left cons' [] l) + *) + let cons_maybe o l = match o with | Some x -> x :: l | None -> l diff --git a/src/core/CCList.mli b/src/core/CCList.mli index 792423d4..4c87874a 100644 --- a/src/core/CCList.mli +++ b/src/core/CCList.mli @@ -40,6 +40,11 @@ val cons_maybe : 'a option -> 'a t -> 'a t [cons_maybe None l] is [l]. @since 0.13 *) +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}. + @since NEXT_RELEASE *) + val (@) : 'a t -> 'a t -> 'a t (** [l1 @ l2] is like [append l1 l2]. Concatenate the two lists [l1] and [l2]. *) diff --git a/src/core/CCListLabels.mli b/src/core/CCListLabels.mli index 66206661..5e038b6c 100644 --- a/src/core/CCListLabels.mli +++ b/src/core/CCListLabels.mli @@ -39,6 +39,11 @@ val append : 'a t -> 'a t -> 'a t (** [append l1 l2] returns the list that is the concatenation of [l1] and [l2]. Safe version of {!List.append}. *) +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}. + @since NEXT_RELEASE *) + val cons_maybe : 'a option -> 'a t -> 'a t (** [cons_maybe (Some x) l] is [x :: l]. [cons_maybe None l] is [l].