On 2/17/23 09:30, Chris Piker wrote:

> operatorG needs
> to be of one of two different types at runtime

std.range.choose may be useful but I think it requires creating two variables like g1 and g2 below:

import std.range;
import std.algorithm;

void main(string[] args) {
    const condition = (args.length > 1);

    // The first part of the algorithm
    auto r = iota(10)
             .filter!(n => n % 2);

    // Two different steps
    auto g1 = r.map!((int n) => n * n);
    auto g2 = r.map!((int n) => n * 10);

    // The rest of the algoritm
    auto result = choose(condition, g1, g2)
                  .array;
}

Ali

Reply via email to