From 43e150c212c311aa9dbf535faa756b34bf7f580a Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Wed, 8 Oct 2014 14:59:52 +0100 Subject: [PATCH] mllib: Add 'combine3' function. --- mllib/common_utils.ml | 6 ++++++ mllib/common_utils.mli | 3 +++ 2 files changed, 9 insertions(+) diff --git a/mllib/common_utils.ml b/mllib/common_utils.ml index d3fec0671..ba39b7072 100644 --- a/mllib/common_utils.ml +++ b/mllib/common_utils.ml @@ -199,6 +199,12 @@ let rec mapi i f = r :: mapi (i + 1) f l let mapi f l = mapi 0 f l +let rec combine3 xs ys zs = + match xs, ys, zs with + | [], [], [] -> [] + | x::xs, y::ys, z::zs -> (x, y, z) :: combine3 xs ys zs + | _ -> invalid_arg "combine3" + (* ANSI terminal colours. *) let ansi_green ?(chan = stdout) () = if TTY.isatty_stdout () then output_string chan "\x1b[0;32m" diff --git a/mllib/common_utils.mli b/mllib/common_utils.mli index 5bf4fbabf..71ccb4c3d 100644 --- a/mllib/common_utils.mli +++ b/mllib/common_utils.mli @@ -53,6 +53,9 @@ val iteri : (int -> 'a -> 'b) -> 'a list -> unit val mapi : (int -> 'a -> 'b) -> 'a list -> 'b list (** Various higher-order functions. *) +val combine3 : 'a list -> 'b list -> 'c list -> ('a * 'b * 'c) list +(** Like {!List.combine} but for triples. All lists must be the same length. *) + val make_message_function : quiet:bool -> ('a, unit, string, unit) format4 -> 'a (** Timestamped progress messages. Used for ordinary messages when not [--quiet]. *)