From 057427cb729a81bf4109cc28b63e03e73444fbe3 Mon Sep 17 00:00:00 2001 From: grayswandyr Date: Tue, 10 Nov 2020 18:58:11 +0100 Subject: [PATCH] Apply suggestions from code review Co-authored-by: Simon Cruanes --- src/core/CCList.ml | 8 +++++--- src/core/CCList.mli | 6 +++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/core/CCList.ml b/src/core/CCList.ml index 2b9147c2..d68c2a06 100644 --- a/src/core/CCList.ml +++ b/src/core/CCList.ml @@ -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 diff --git a/src/core/CCList.mli b/src/core/CCList.mli index fad47f17..785ce944 100644 --- a/src/core/CCList.mli +++ b/src/core/CCList.mli @@ -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 =