mirror of
https://github.com/c-cube/iter.git
synced 2025-12-05 19:00:31 -05:00
distinction diagonal,diagonal_l
This commit is contained in:
parent
4748655708
commit
67a40a4882
3 changed files with 26 additions and 7 deletions
|
|
@ -463,14 +463,23 @@ let product outer inner k =
|
|||
let product2 outer inner k =
|
||||
outer (fun x -> inner (fun y -> k x y))
|
||||
|
||||
let rec diagonal l yield = match l with
|
||||
let rec diagonal_l l yield = match l with
|
||||
| [] -> ()
|
||||
| x::tail ->
|
||||
List.iter (fun y -> yield (x,y)) tail;
|
||||
diagonal tail yield
|
||||
diagonal_l tail yield
|
||||
|
||||
(*$=
|
||||
[0,1; 0,2; 1,2] (diagonal [0;1;2] |> to_list)
|
||||
[0,1; 0,2; 1,2] (diagonal_l [0;1;2] |> to_list)
|
||||
*)
|
||||
|
||||
let diagonal seq =
|
||||
let l = ref [] in
|
||||
seq (fun x -> l := x :: !l);
|
||||
diagonal_l (List.rev !l)
|
||||
|
||||
(*$=
|
||||
[0,1; 0,2; 1,2] (of_list [0;1;2] |> diagonal |> to_list)
|
||||
*)
|
||||
|
||||
let join ~join_row s1 s2 k =
|
||||
|
|
|
|||
|
|
@ -251,9 +251,14 @@ val product : 'a t -> 'b t -> ('a * 'b) t
|
|||
as required (several times), possibly by calling {!persistent} on it
|
||||
beforehand. *)
|
||||
|
||||
val diagonal : 'a list -> ('a * 'a) t
|
||||
val diagonal_l : 'a list -> ('a * 'a) t
|
||||
(** All pairs of distinct positions of the list. [diagonal l] will
|
||||
return the list of [List.nth i l, List.nth j l] if [i < j].
|
||||
return the sequence of all [List.nth i l, List.nth j l] if [i < j].
|
||||
@since NEXT_RELEASE *)
|
||||
|
||||
val diagonal : 'a t -> ('a * 'a) t
|
||||
(** All pairs of distinct positions of the sequence.
|
||||
Iterates only once on the sequence, which must be finite.
|
||||
@since NEXT_RELEASE *)
|
||||
|
||||
val product2 : 'a t -> 'b t -> ('a, 'b) t2
|
||||
|
|
|
|||
|
|
@ -222,9 +222,14 @@ val product : 'a t -> 'b t -> ('a * 'b) t
|
|||
as required (several times), possibly by calling {!persistent} on it
|
||||
beforehand. *)
|
||||
|
||||
val diagonal : 'a list -> ('a * 'a) t
|
||||
val diagonal_l : 'a list -> ('a * 'a) t
|
||||
(** All pairs of distinct positions of the list. [diagonal l] will
|
||||
return the list of [List.nth i l, List.nth j l] if [i < j].
|
||||
return the sequence of all [List.nth i l, List.nth j l] if [i < j].
|
||||
@since NEXT_RELEASE *)
|
||||
|
||||
val diagonal : 'a t -> ('a * 'a) t
|
||||
(** All pairs of distinct positions of the sequence.
|
||||
Iterates only once on the sequence, which must be finite.
|
||||
@since NEXT_RELEASE *)
|
||||
|
||||
val product2 : 'a t -> 'b t -> ('a, 'b) t2
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue