mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 11:15:31 -05:00
add CCLazy_list.take
This commit is contained in:
parent
560cba9754
commit
c3e0f81f7e
2 changed files with 14 additions and 1 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue