digitalmars.D.learn - Turn function into infinite range
- Martin Nowak (9/9) Sep 29 2014 Does anyone know a construct to turn a lambda into an infinite range.
- Brad Anderson (7/18) Sep 29 2014 I can't find anything to do it. That seems weirdly absent. You
- monarch_dodra (14/16) Sep 29 2014 AFAIK, this as never existed.
- monarch_dodra (3/4) Sep 29 2014 I threw something together, and it really works exceptionally
- Daniel =?UTF-8?B?S296w6Fr?= via Digitalmars-d-learn (4/16) Sep 29 2014 V Mon, 29 Sep 2014 19:02:36 +0200
- monarch_dodra (4/22) Sep 29 2014 That just repeats the value, but doesn't re-evaluate the value on
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.
Sep 29 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);
Sep 29 2014
On Monday, 29 September 2014 at 17:02:43 UTC, Martin Nowak wrote:I though I've seen this around somewhere but can no longer find it.AFAIK, this as never existed. We recently merged in "cache" into phobos. This seems like a prime candidate to expand to also take a function/delegate, as on of its built-in feature is that the value of "front" is not changed until "popFront()" is called. Having it also accept a function/delegate would make sense. The issue with *not* having that is that a "dumb" adapter would fail the: r.front == r.front Test. And I'm pretty sure this test is expected to pass, even for the so called "transient" ranges. I think I'll get to it now (this week). Thoughts?
Sep 29 2014
On Monday, 29 September 2014 at 20:02:19 UTC, monarch_dodra wrote:I think I'll get to it now (this week).I threw something together, and it really works exceptionally well. Will file PR soon.
Sep 29 2014
V Mon, 29 Sep 2014 19:02:36 +0200 Martin Nowak via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> napsáno: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.
Sep 29 2014
On Monday, 29 September 2014 at 21:16:27 UTC, Daniel Kozák via Digitalmars-d-learn wrote:V Mon, 29 Sep 2014 19:02:36 +0200 Martin Nowak via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> napsáno:That just repeats the value, but doesn't re-evaluate the value on every call to front/popFront.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.
Sep 29 2014