This example starts a collection with the pairs (x, x+1) and (x+1, x) for x in 0 .. 10. It then adds pairs (y, z) for which (x, y) and (x, z) are present. Because the initial pairs are symmetric, this should result in all pairs (x, y) for x and y in 0 .. 11.
import std.algorithm : map; import std.range : iota; // arrange Iteration iter; auto variable = iter.variable!(int, int)("source"); variable.insert(iota(3).map!(x => kvTuple(x, x + 1))); // [[0,1],[1,2],[2,3],] variable.insert(iota(3).map!(x => kvTuple(x + 1, x))); // [[1,0],[2,1],[3,2],] // act while (iter.changed) { variable.fromJoin!((k, v1, v2) => kvTuple(v1, v2))(variable, variable); } auto result = variable.complete; // assert result.should == [[0, 0], [0, 1], [0, 2], [0, 3], [1, 0], [1, 1], [1, 2], [1, 3], [2, 0], [2, 1], [2, 2], [2, 3], [3, 0], [3, 1], [3, 2], [3, 3]].map!( a => kvTuple(a[0], a[1]));
Adds tuples that result from joining input1 and input2.