import std.stdio, std.algorithm, std.range;
/// flip2!foo(a, b, c...) === foo(b, a, c...)
template flip2(alias callable) {
auto flip2(T2, T1n...)(T2 y, T1n others)
if (T1n.length > 0) {
return callable(others[0], y, others[1 .. $]);
}
}
void main() {
reduce!q{a * b}(1, iota(1, 10))
.writeln;
iota(1, 10)
.flip2!(reduce!q{a * b})(1)
.writeln;
}
Bye,
bearophile
This is not a real use case because the reduce!() of Phobos will
be fixed for UCFS, but sometimes you can't swap the arguments of
a function:
- writeln, UFCS and flip bearophile
- Re: writeln, UFCS and flip bearophile
- Re: writeln, UFCS and flip ixid
- Re: writeln, UFCS and flip ixid
- Re: writeln, UFCS and flip bearophile
- Re: writeln, UFCS and flip Timon Gehr
- Re: writeln, UFCS and flip bearophile
- Re: writeln, UFCS and flip ixid
- Re: writeln, UFCS and flip bearophile
- Re: writeln, UFCS and flip Tyro[17]
- Re: writeln, UFCS and flip bearophile
- Re: writeln, UFCS and flip Timon Gehr
