map question
Stanislav Blinov
stanislav.blinov at gmail.com
Sun Jan 23 09:08:46 UTC 2022
On Saturday, 22 January 2022 at 23:54:27 UTC, forkit wrote:
> On Saturday, 22 January 2022 at 19:55:43 UTC, Stanislav Blinov
> wrote:
>>
>
> thanks for the explanation. That really helped :-)
>
> writeln( generate!(() => dice(0.6, 1.4)).take(howManyTimes) );
> [1, 1, 1, 1, 0]
>
> (or after reading Ali's response - getting rid of rnd, and
> using _ )
>
> writeln( howManyTimes.iota.map!(_ => dice(0.6, 1.4)) );
> [1, 0, 1, 1, 1]
>
> They produce exactly the same thing, so I guess it comes down
> to personal choice now.
Using `iota` here incurs additional computation and argument
copies that are actually never used, i.e. wasted work. So I'd say
go with `generate`, as that seems the intent.
More information about the Digitalmars-d-learn
mailing list