flipFlop

Returns a lazy input range that alterntively returns the state of one of two sub-ranges.

Similar to std.range roundRobin() or chain() except that the resulting range is considered as empty when one of the sub range is consumed.

flipFlop
(
R1
R2
)
(
auto ref R1 flip
,
auto ref R2 flop
)
if (
isInputRange!R1 &&
isInputRange!R2
&&
is(ElementType!R1 == ElementType!R2)
)

Parameters

flip
Type: R1

the first input range.

flop
Type: R2

the second input range.

Examples

1 import std.array: array;
2 assert(flipFlop([0,2,4],[1,3,5]).array == [0,1,2,3,4,5]);
3 assert(flipFlop([0,2],[1,3,5]).array == [0,1,2,3]);
4 assert(flipFlop([0,2,4],[1,3]).array == [0,1,2,3,4]);
5 int[] re = [];
6 assert(flipFlop([0], re).array == [0]);
7 assert(flipFlop(re, re).array == []);
8 assert(flipFlop(re, [0]).array == []);

Meta