"fold": a replacement for "reduce"
bearophile
bearophileHUGS at lycos.com
Mon Mar 31 09:58:37 PDT 2014
monarch_dodra:
> uint[] foo3(const(uint[])[] X)
> {
> assert(!X.empty);
> auto seed = X.front.dup;
> X.popFront();
> return reduce!((i, j) => i[] |= j[])
> (seed, X);
> }
> //----
>
> This gives the same "logical" result, but reuses the seed
> contents on every iteration.
Nice, thank you :-)
And with a miniscule de-optimization it becomes very good:
https://d.puremagic.com/issues/show_bug.cgi?id=10523
Bye,
bearophile
More information about the Digitalmars-d
mailing list