mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-07 03:35:30 -05:00
CCList.filter
This commit is contained in:
parent
021508968c
commit
bc40893166
2 changed files with 16 additions and 0 deletions
|
|
@ -61,6 +61,19 @@ let append l1 l2 =
|
|||
|
||||
let (@) = append
|
||||
|
||||
let filter p l =
|
||||
let rec direct i p l = match l with
|
||||
| [] -> []
|
||||
| _ when i=0 -> safe p l []
|
||||
| x::l' when not (p x) -> direct i p l'
|
||||
| x::l' -> x :: direct (i-1) p l'
|
||||
and safe p l acc = match l with
|
||||
| [] -> List.rev acc
|
||||
| x::l' when not (p x) -> safe p l' acc
|
||||
| x::l' -> safe p l' (x::acc)
|
||||
in
|
||||
direct _direct_depth p l
|
||||
|
||||
let fold_right f l acc =
|
||||
let rec direct i f l acc = match l with
|
||||
| [] -> acc
|
||||
|
|
|
|||
|
|
@ -36,6 +36,9 @@ val append : 'a t -> 'a t -> 'a t
|
|||
|
||||
val (@) : 'a t -> 'a t -> 'a t
|
||||
|
||||
val filter : ('a -> bool) -> 'a t -> 'a t
|
||||
(** Safe version of {!List.filter} *)
|
||||
|
||||
val fold_right : ('a -> 'b -> 'b) -> 'a t -> 'b -> 'b
|
||||
(** Safe version of [fold_right] *)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue