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:

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

Reply via email to