summaryrefslogtreecommitdiff
path: root/src/Collections.ml
diff options
context:
space:
mode:
authorSon Ho2022-01-29 20:35:44 +0100
committerSon Ho2022-01-29 20:35:44 +0100
commitde0431f31d77a53445a6731560a25c24b52384bf (patch)
tree0822cf604d2a865e8ef2e4e0cd7144410e107130 /src/Collections.ml
parent79af7f999e3a41e3c5f9a30819a7cc43b5397c56 (diff)
Cleanup a bit
Diffstat (limited to 'src/Collections.ml')
-rw-r--r--src/Collections.ml17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/Collections.ml b/src/Collections.ml
index bb7c37f1..125cab1f 100644
--- a/src/Collections.ml
+++ b/src/Collections.ml
@@ -38,6 +38,23 @@ module List = struct
(** Return the n first elements of the list *)
let prefix (n : int) (ls : 'a list) : 'a list = fst (split_at ls n)
+
+ (** Iter and link the iterations.
+
+ Iterate over a list, but call a function between every two elements
+ (but not before the first element, and not after the last).
+ *)
+ let iter_link (link : unit -> unit) (f : 'a -> unit) (ls : 'a list) : unit =
+ let rec iter ls =
+ match ls with
+ | [] -> ()
+ | [ x ] -> f x
+ | x :: y :: ls ->
+ f x;
+ link ();
+ iter (y :: ls)
+ in
+ iter ls
end
module type OrderedType = sig