Skip to content

Commit

Permalink
instead of a pair of enums, Enum.combine now takes two enums (it was …
Browse files Browse the repository at this point in the history
…curried)
  • Loading branch information
Francois Berenger authored and gasche committed Apr 27, 2016
1 parent fa91f54 commit 310d2b5
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
9 changes: 8 additions & 1 deletion ChangeLog
Expand Up @@ -16,7 +16,14 @@ Changelog
- BatArray: add split : 'a BatOrd.ord -> 'a array -> 'a -> int * int
search for the range equal to a given element in a sorted array
#443, #470
(Simon Cruanes, Gabriel Scherer, request by Francois Berenger)
(Simon Cruanes, Gabriel Scherer, request by François Berenger)
- BatEnum: BatEnum.combine is now curried, just like List.combine,
its signature changes from:
val combine: 'a t * 'b t -> ('a * 'b) t
to
val combine: 'a t -> 'b t -> ('a * 'b) t
#578
(François Berenger)

## v2.4.0

Expand Down
10 changes: 5 additions & 5 deletions src/batEnum.ml
Expand Up @@ -868,8 +868,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 @@ -881,11 +881,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
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
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

0 comments on commit 310d2b5

Please sign in to comment.