This commit is contained in:
Simon Cruanes 2014-07-18 02:55:53 +02:00
parent 556d10a0d4
commit 78551b5e84

View file

@ -52,6 +52,12 @@ let repeat ?n x = match n with
| None -> _forever x
| Some n -> _repeat n x
(*$T
repeat ~n:4 0 |> to_list = [0;0;0;0]
repeat ~n:0 1 |> to_list = []
repeat 1 |> take 20 |> to_list = (repeat ~n:20 1 |> to_list)
*)
let is_empty l = match l () with
| `Nil -> true
| `Cons _ -> false
@ -141,6 +147,10 @@ let rec append l1 l2 () = match l1 () with
let rec cycle l () = append l (cycle l) ()
(*$T
cycle (of_list [1;2]) |> take 5 |> to_list = [1;2;1;2;1]
*)
let rec flat_map f l () = match l () with
| `Nil -> `Nil
| `Cons (x, l') ->