CCList.filter

This commit is contained in:
Simon Cruanes 2014-06-11 21:54:01 +02:00
parent 021508968c
commit bc40893166
2 changed files with 16 additions and 0 deletions

View file

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

View file

@ -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] *)