diff --git a/src/iter/CCLazy_list.ml b/src/iter/CCLazy_list.ml index a1d94cf0..a258f372 100644 --- a/src/iter/CCLazy_list.ml +++ b/src/iter/CCLazy_list.ml @@ -50,8 +50,17 @@ let filter ~f l = (*$= [2;4;6] (of_list [1;2;3;4;5;6;7] |> filter ~f:(fun x -> x mod 2=0) |> to_list) + [2;4;6] (of_gen Gen.(1 -- max_int) |> filter ~f:(fun x -> x mod 2=0) |> take 3 |> to_list) *) +let rec take n l = + lazy ( + match l with + | _ when n=0 -> Nil + | lazy Nil -> Nil + | lazy (Cons (x,tl)) -> Cons (x, take (n-1) tl) + ) + let rec append a b = lazy ( match a with diff --git a/src/iter/CCLazy_list.mli b/src/iter/CCLazy_list.mli index 77c7870d..613be3fe 100644 --- a/src/iter/CCLazy_list.mli +++ b/src/iter/CCLazy_list.mli @@ -32,7 +32,11 @@ val map : f:('a -> 'b) -> 'a t -> 'b t (** Lazy map *) val filter : f:('a -> bool) -> 'a t -> 'a t -(** Filter values +(** Filter values. + @since NEXT_RELEASE *) + +val take : int -> 'a t -> 'a t +(** Take at most n values. @since NEXT_RELEASE *) val append : 'a t -> 'a t -> 'a t