xxxxxxxxxx
void main() {
import std.experimental.all;
auto xs = only(1, 2, 3);
int a = 2, b = 3;
xs.pack(a, b).map!(unpack!((x, a, b) => x * a * b));
}
auto pack(T, Captures...)(T arg, Captures captures) {
string mix(int n) {
import std.conv: to;
string s = "zip(arg,";
foreach (i; 0 .. n) {
s ~= "repeat(captures[" ~ i.to!string ~ "]),";
}
s ~= ")";
return s;
}
import std.range: repeat, zip;
return mixin(mix(Captures.length));
}
template unpack(alias func) {
import std.typecons: isTuple;
auto unpack(TupleType)(TupleType tup) if (isTuple!TupleType) {
return func(tup.expand);
}
}