diff --git a/ChangeLog b/ChangeLog index 267d60380..91ac3f2a0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -10,7 +10,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.5.0 diff --git a/src/batEnum.ml b/src/batEnum.ml index 344000aad..8ca9d08f4 100644 --- a/src/batEnum.ml +++ b/src/batEnum.ml @@ -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) ; @@ -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 *) diff --git a/src/batEnum.mli b/src/batEnum.mli index 07469c873..9392c31f8 100644 --- a/src/batEnum.mli +++ b/src/batEnum.mli @@ -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] *) diff --git a/testsuite/test_modifiable.ml b/testsuite/test_modifiable.ml index b0ad1f469..edfc8f77a 100644 --- a/testsuite/test_modifiable.ml +++ b/testsuite/test_modifiable.ml @@ -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)) @@ -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)) @@ -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)) @@ -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)) @@ -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))