ZipWith

Zips one or more $(D_PSYMBOL Pack)s with f.

Given f and tuples t1, t2, ..., tk, where tki denotes the i-th element of the tuple k-th tuple, $(D_PSYMBOL ZipWith) produces a sequence:

f(t1[0], t2[0], ... tk[0]),
f(t1[1], t2[1], ... tk[1]),
...
f(tk[0], tk[1], ... tk[i]),

$(D_PSYMBOL ZipWith) begins with the first elements from Packs and applies f to them, then it takes the second ones and does the same, and so on.

If not all argument tuples have the same length, $(D_PSYMBOL ZipWith) will zip only n elements from each tuple, where n is the length of the shortest tuple in the argument list. Remaining elements in the longer tuples are just ignored.

template ZipWith (
Packs...
) if (
Packs.length > 0 &&
__traits(isTemplate, f)
&&
(
allSatisfy!(ApplyLeft!(isInstanceOf, Pack), Packs) ||
allSatisfy!(ApplyLeft!(isInstanceOf, Tuple), Packs)
)
) {}

Members

Aliases

ZipWith
alias ZipWith = Iterate!(0, Packs)
Undocumented in source.

Parameters

f

Some template that can be applied to the elements of Packs.

Packs

$(D_PSYMBOL Pack) instances.

Return Value

A sequence, whose i-th element contains the i-th element from each of the Packs.

Examples

alias Result1 = ZipWith!(AliasSeq, Pack!(1, 2), Pack!(5, 6), Pack!(9, 10));
static assert(Result1 == AliasSeq!(1, 5, 9, 2, 6, 10));

alias Result2 = ZipWith!(AliasSeq, Pack!(1, 2, 3), Pack!(4, 5));
static assert(Result2 == AliasSeq!(1, 4, 2, 5));

alias Result3 = ZipWith!(AliasSeq, Pack!(), Pack!(4, 5));
static assert(Result3.length == 0);

Meta