utop # module S = Sequence;;
module S = Sequence
utop # open Containers;;
utop # let s =
List.product (fun x y -> (x, y)) [ "a"; "b"; "c" ] [ "d"; "e"; "f" ]
|> S.of_list;;
val s : (string * string) S.t = <fun>
utop # let print s = Format.printf "%a"
(Format.within "[" "]" @@ S.pp_seq
@@ Format.within "(" ")" @@ Pair.pp String.print String.print) s;;
val print : (string * string) S.t -> unit = <fun>
utop # print s;;
[("a", "d"), ("a", "e"), ("a", "f"), ("b", "d"), ("b", "e"), ("b", "f"), ("c",
"d"), ("c", "e"), ("c",
"f")]- : unit = ()
utop # let s2 = S.group_by ~hash:(Hash.pair String.hash String.hash)
~eq:(fun (a1, _) (b1, _) -> String.equal a1 b1) s;;
val s2 : (string * string) list S.t = <fun>
utop # let print2 s =
S.iter Format.(printf "%a@\n" (Format.within "[" "]" @@ list @@ within "(" ")"
@@ hbox @@ Pair.pp String.print String.print)) s;;
val print2 : (string * string) list S.t -> unit = <fun>
utop # print2 s2;;
[("b", "d")]
[("a", "e")]
[("b", "f")]
[("a", "d")]
[("c", "d")]
[("a", "f")]
[("c", "f")]
[("c", "e")]
[("b", "e")]
- : unit = ()
utop # let s3 = S.sort_uniq ~cmp:(Pair.compare String.compare String.compare) s
|> S.group_succ_by ~eq:(fun (a1, _) (b1, _) -> String.equal a1 b1);;
val s3 : (string * string) list S.t = <fun>
utop # print2 s3;;
[("a", "f"), ("a", "e"), ("a", "d")]
[("b", "f"), ("b", "e"), ("b", "d")]
[("c", "f"), ("c", "e"),
("c", "d")]
- : unit = ()