mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 11:15:31 -05:00
Apply suggestions from code review
Co-authored-by: Simon Cruanes <simon.cruanes.2007@m4x.org>
This commit is contained in:
parent
3912b288e8
commit
057427cb72
2 changed files with 8 additions and 6 deletions
|
|
@ -572,14 +572,16 @@ let combine_gen l1 l2 =
|
|||
res1 = res2)
|
||||
*)
|
||||
|
||||
let combine_chop l1 l2 =
|
||||
let combine_shortest l1 l2 =
|
||||
let rec direct i l1 l2 = match l1, l2 with
|
||||
| (_, []) | ([], _) -> []
|
||||
| _ when i=0 -> safe l1 l2 []
|
||||
| (x1::l1', x2::l2') -> (x1, x2) :: direct (i-1) l1' l2'
|
||||
and safe l1 l2 acc = match l1, l2 with
|
||||
| ([], _) | (_, []) -> List.rev acc
|
||||
| (x1::l1', x2::l2') -> safe l1' l2' @@ (x1, x2) :: acc
|
||||
| (x1::l1', x2::l2') ->
|
||||
let acc = (x1,x2) :: acc in
|
||||
safe l1' l2' acc
|
||||
in
|
||||
direct direct_depth_default_ l1 l2
|
||||
|
||||
|
|
@ -1810,7 +1812,7 @@ module Infix = struct
|
|||
let[@inline] monoid_product l1 l2 = product (fun x y -> x,y) l1 l2
|
||||
end)
|
||||
|
||||
let (and&) = combine_chop
|
||||
let (and&) = combine_shortest
|
||||
end
|
||||
|
||||
include Infix
|
||||
|
|
|
|||
|
|
@ -138,8 +138,8 @@ val combine_gen : 'a list -> 'b list -> ('a * 'b) gen
|
|||
@since 1.2, but only
|
||||
@since 2.2 with labels *)
|
||||
|
||||
val combine_chop : 'a list -> 'b list -> ('a * 'b) list
|
||||
(** [combine [a1; …; am] [b1; …; bn]] is [[(a1,b1); …; (am,bm)]] if m <= n.
|
||||
val combine_shortest : 'a list -> 'b list -> ('a * 'b) list
|
||||
(** [combine_shortest [a1; …; am] [b1; …; bn]] is [[(a1,b1); …; (am,bm)]] if m <= n.
|
||||
Like {!combine} but stops at the shortest list rather than raising.
|
||||
@since 3.1 *)
|
||||
|
||||
|
|
@ -861,7 +861,7 @@ module Infix : sig
|
|||
include CCShimsMkLet_.S with type 'a t_let := 'a list
|
||||
|
||||
val (and&) : 'a list -> 'b list -> ('a * 'b) list
|
||||
(** [(and&)] is [combine_chop]. It allows to perform a synchronized product between two lists,
|
||||
(** [(and&)] is [combine_shortest]. It allows to perform a synchronized product between two lists,
|
||||
stopping gently at the shortest. Usable both with [let+] and [let*].
|
||||
{[
|
||||
# let f xs ys zs =
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue