Infinite range of nullable elements

2015-07-17 Thread Roland Hadinger via Digitalmars-d-learn
At this moment I'm tempted to implement a function taking a range of elements E and returning an infinite range of Nullable!E. With this function ("cushion" for a lack of better name) I could do: auto a = [0,1,2,3,4,5,6,7,8,9]; foreach (e ; a.cushion.take(20)) writeln(e); //

Re: Infinite range of nullable elements

2015-07-17 Thread via Digitalmars-d-learn
On Friday, 17 July 2015 at 07:42:09 UTC, Roland Hadinger wrote: At this moment I'm tempted to implement a function taking a range of elements E and returning an infinite range of Nullable!E. [...] Wouldn't it still require the algorithms to check if an element isNull()? Calling get() on a n

Re: Infinite range of nullable elements

2015-07-17 Thread anonymous via Digitalmars-d-learn
On Friday, 17 July 2015 at 07:42:09 UTC, Roland Hadinger wrote: Here's how I would implement the basic behaviour (could be extended to also forward bidirectional and random access functions): --- auto cushion(R)(R r) if (isInputRange!R) { static if (isInfinite!R) { retu

Re: Infinite range of nullable elements

2015-07-17 Thread Roland Hadinger via Digitalmars-d-learn
On Friday, 17 July 2015 at 10:19:22 UTC, Márcio Martins wrote: On Friday, 17 July 2015 at 07:42:09 UTC, Roland Hadinger wrote: At this moment I'm tempted to implement a function taking a range of elements E and returning an infinite range of Nullable!E. [...] Wouldn't it still require the a

Re: Infinite range of nullable elements

2015-07-17 Thread Roland Hadinger via Digitalmars-d-learn
On Friday, 17 July 2015 at 12:44:57 UTC, anonymous wrote: The building blocks are there. You're `map`ping the original range to `Nullable`, and then you're `chain`ing an infinite range (`cycle`) of nulls behind. import std.range: isInputRange; auto cushion(R)(R r) if (isInputRange!R)