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 R1

the first input range.

flop R2

the second input range.

Examples

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

Meta