From 6b0acbf27a13ebff659e3ac36bb67ba20b1b068d Mon Sep 17 00:00:00 2001
From: Basile Desloges <basile.desloges@cea.fr>
Date: Thu, 2 Sep 2021 10:42:19 +0200
Subject: [PATCH] [kernel] Add `nest` and `flatten` to `Extlib` to manipulate
 tuples

---
 src/libraries/stdlib/extlib.ml  |  8 ++++++++
 src/libraries/stdlib/extlib.mli | 11 +++++++++++
 2 files changed, 19 insertions(+)

diff --git a/src/libraries/stdlib/extlib.ml b/src/libraries/stdlib/extlib.ml
index 51d4e1917ed..e6267f35c0f 100644
--- a/src/libraries/stdlib/extlib.ml
+++ b/src/libraries/stdlib/extlib.ml
@@ -77,6 +77,14 @@ let uncurry f x = f (fst x) (snd x)
 let iter_uncurry2 iter f v =
   iter (fun a b -> f (a, b)) v
 
+(* ************************************************************************* *)
+(** {2 Tuples} *)
+(* ************************************************************************* *)
+
+let nest b (a, c) = (a, b), c
+
+let flatten ((a, b), c) = a, b, c
+
 (* ************************************************************************* *)
 (** {2 Lists} *)
 (* ************************************************************************* *)
diff --git a/src/libraries/stdlib/extlib.mli b/src/libraries/stdlib/extlib.mli
index 79addc0d2c0..1ef17c991ac 100644
--- a/src/libraries/stdlib/extlib.mli
+++ b/src/libraries/stdlib/extlib.mli
@@ -77,6 +77,17 @@ val iter_uncurry2:
   (('a -> 'b -> unit) -> 'c -> unit) ->
   (('a * 'b -> unit) -> 'c -> unit)
 
+(* ************************************************************************* *)
+(** {2 Tuples} *)
+(* ************************************************************************* *)
+
+val nest: 'b -> 'a * 'c -> ('a * 'b) * 'c
+(** Nest the first argument with the first element of the pair given as second
+    argument. *)
+
+val flatten: ('a * 'b) * 'c -> 'a * 'b * 'c
+(** Flatten the pairs into a triplet. *)
+
 (* ************************************************************************* *)
 (** {2 Lists} *)
 (* ************************************************************************* *)
-- 
GitLab