mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 11:15:31 -05:00
Add CCSeq.zip_with
This commit is contained in:
parent
569e254540
commit
4aed639cc7
2 changed files with 18 additions and 0 deletions
|
|
@ -341,6 +341,18 @@ let rec zip a b () = match a(), b() with
|
|||
| _, Nil -> Nil
|
||||
| Cons (x, a'), Cons (y, b') -> Cons ((x,y), zip a' b')
|
||||
|
||||
let rec zip_with f a b () = match a(), b() with
|
||||
| Nil, _
|
||||
| _, Nil -> Nil
|
||||
| Cons (x, a'), Cons (y, b') -> Cons (f x y, zip_with f a' b')
|
||||
|
||||
(*$Q
|
||||
Q.(pair (list int) (list int)) (fun (l1, l2) -> \
|
||||
let l1 = of_list l1 in \
|
||||
let l2 = of_list l2 in \
|
||||
zip l1 l2 |> to_list = (zip_with (fun x y -> (x, y)) l1 l2 |> to_list))
|
||||
*)
|
||||
|
||||
let unzip l =
|
||||
let rec first l () = match l() with
|
||||
| Nil -> Nil
|
||||
|
|
|
|||
|
|
@ -178,6 +178,12 @@ val zip : 'a t -> 'b t -> ('a * 'b) t
|
|||
(** Combine elements pairwise. Stop as soon as one of the lists stops.
|
||||
@since 0.13 *)
|
||||
|
||||
val zip_with : ('a -> 'b -> 'c) -> 'a t -> 'b t -> 'c t
|
||||
(** Generalization of {!zip}. Combine elements with the function given as the first
|
||||
argument. Stop as soon as one of the lists stops.
|
||||
|
||||
@since NEXT_RELEASE *)
|
||||
|
||||
val unzip : ('a * 'b) t -> 'a t * 'b t
|
||||
(** Split each tuple in the list.
|
||||
@since 0.13 *)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue