Patterns to avoid GC with capturing closures?

Paul Backus snarwin at gmail.com
Sun Aug 26 18:35:44 UTC 2018


On Sunday, 26 August 2018 at 06:08:39 UTC, vit wrote:
>     const x = iota(0, 10)
>         .map!((x, i) => x*i)(a)   ///map!((x) => x*a)
>         .map!((x, i) => x*i)(b)   ///map!((x) => x*b)
>         .filter!((x, i) => x%i)(c)///filter!((x) => x%c)
>         .any!(x => x % c);

I think it's easier to just use zip than to reimplement large 
chunks of std.algorithm:

const x = iota(0, 10)
     .zip!(repeat(a), repeat(b))
     .map!(unpack!((x, a, b) => x*a*b))
     .zip!(repeat(c))
     .filter!(unpack!((x, c) => x%c)) // redundant with `any`
     .any!(unpack!((x, c) => x%c))


More information about the Digitalmars-d-learn mailing list