Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

instead of a pair of enums, Enum.combine now takes two enums (it was cur... #578

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/batEnum.ml
Original file line number Diff line number Diff line change
Expand Up @@ -856,8 +856,8 @@ let min_count x y =
| Some c, None | None, Some c -> c
| Some c1, Some c2 -> min c1 c2

let combine (x,y) =
if x.fast && y.fast then (*Optimized case*)
let combine x y =
if x.fast && y.fast then (* Optimized case *)
let rec aux (x,y) =
{
count = (fun () -> min_count x y) ;
Expand All @@ -869,11 +869,11 @@ let combine (x,y) =
else from (fun () -> (x.next(), y.next()))

(*$T
combine (List.enum [1;2;3], List.enum ["a";"b"]) \
combine (List.enum [1;2;3]) ( List.enum ["a";"b"]) \
|> List.of_enum = [1, "a"; 2, "b"]
combine (List.enum [1;2;3], repeat "a") \
combine (List.enum [1;2;3]) ( repeat "a") \
|> List.of_enum = [1,"a"; 2,"a"; 3,"a"]
combine (List.enum [1;2;3], repeat "a") \
combine (List.enum [1;2;3]) ( repeat "a") \
|> Enum.count = 3
*)

Expand Down
10 changes: 6 additions & 4 deletions src/batEnum.mli
Original file line number Diff line number Diff line change
Expand Up @@ -559,10 +559,12 @@ val dup : 'a t -> 'a t * 'a t
that stream is a destructive data structure, the point of [dup] is to
return two streams can be used independently. *)

val combine : 'a t * 'b t -> ('a * 'b) t
(** [combine] transform a pair of stream into a stream of pairs of corresponding
elements. If one stream is short, excess elements of the longer stream are
ignored. *)
val combine : 'a t -> 'b t -> ('a * 'b) t
(** [combine] transform two streams into a stream of pairs of corresponding
elements. If one stream is shorter, excess elements of the longer stream are
ignored.
Curried @since 3.0
*)

val uncombine : ('a * 'b) t -> 'a t * 'b t
(** [uncombine] is the opposite of [combine] *)
Expand Down
10 changes: 5 additions & 5 deletions testsuite/test_modifiable.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ let none _ = None
module TestModifiable_mutable (M : MODIFIABLE_MUTABLE) =
struct
let test () =
let m = M.of_enum (Enum.combine (1 -- 5, 1 -- 5)) in
let m = M.of_enum (Enum.combine (1 -- 5) (1 -- 5)) in
M.modify 2 succ m ;
let e = M.enum m /@ snd |> List.of_enum |> List.sort Int.compare in
assert_equal ~printer:(BatIO.to_string (List.print Int.print))
Expand Down Expand Up @@ -64,7 +64,7 @@ let rec reapply_i mi ma f m =
module TestModifiable_immutable (M : MODIFIABLE_IMMUTABLE) =
struct
let test () =
let m = M.of_enum (Enum.combine (1 -- 5, 1 -- 5)) in
let m = M.of_enum (Enum.combine (1 -- 5) (1 -- 5)) in
let m = M.modify 2 succ m in
let e = M.enum m /@ snd |> List.of_enum |> List.sort Int.compare in
assert_equal ~printer:(BatIO.to_string (List.print Int.print))
Expand Down Expand Up @@ -118,7 +118,7 @@ end
module TestModifiable_poly_immutable (M : MODIFIABLE_POLY_IMMUTABLE) =
struct
let test () =
let m = M.of_enum (Enum.combine (1 -- 5, 1 -- 5)) in
let m = M.of_enum (Enum.combine (1 -- 5) (1 -- 5)) in
let m = M.modify 2 succ m in
let e = M.enum m /@ snd |> List.of_enum |> List.sort Int.compare in
assert_equal ~printer:(BatIO.to_string (List.print Int.print))
Expand Down Expand Up @@ -165,7 +165,7 @@ end
module TestModifiable_poly_multi_immutable (M : MODIFIABLE_POLY_MULTI_IMMUTABLE) =
struct
let test () =
let m = M.of_enum (Enum.combine (1 -- 5, 1 -- 5)) in
let m = M.of_enum (Enum.combine (1 -- 5) (1 -- 5)) in
let m = M.modify 2 (BatSet.PSet.map succ) m in
let e = M.enum m /@ snd |> List.of_enum |> List.sort Int.compare in
assert_equal ~printer:(BatIO.to_string (List.print Int.print))
Expand Down Expand Up @@ -204,7 +204,7 @@ end
module TestModifiable_multi_immutable (M : MODIFIABLE_MULTI_IMMUTABLE) =
struct
let test () =
let m = M.of_enum (Enum.combine (1 -- 5, 1 -- 5)) in
let m = M.of_enum (Enum.combine (1 -- 5) (1 -- 5)) in
let m = M.modify 2 (BatSet.map succ) m in
let e = M.enum m /@ snd |> List.of_enum |> List.sort Int.compare in
assert_equal ~printer:(BatIO.to_string (List.print Int.print))
Expand Down