Turn function into infinite range
Brad Anderson via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Sep 29 10:11:43 PDT 2014
On Monday, 29 September 2014 at 17:02:43 UTC, Martin Nowak wrote:
> Does anyone know a construct to turn a lambda into an infinite
> range.
>
> import std.random;
>
> unittest
> {
> Random gen;
> foreach(v; xxx!(() => uniform(0, 100, gen)).take(10))
> writeln(v);
> }
>
> I though I've seen this around somewhere but can no longer find
> it.
I can't find anything to do it. That seems weirdly absent. You
can abuse recurrence to do it.
Random gen;
foreach(v; recurrence!((a, n) => uniform(0, 100,
gen))(0).dropOne.take(10))
writeln(v);
More information about the Digitalmars-d-learn
mailing list