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)
{
    import std.algorithm: map;
    import std.range: chain, cycle, ElementType, only;
    import std.typecons: Nullable;

    alias E = ElementType!R;
    alias NE = Nullable!E;

    return chain(r.map!NE, NE().only.cycle);
}
----

Nice! I didn't think of using 'chain'.

Reply via email to