---
import core.thread;
import std.conv;
import std.stdio;

void formatStuff(P)(P put, int stuff)
{
    put("a");
    put("b");
    put("c");
    put(stuff);
    foreach (i; 0 .. 10)
    {
        put(i ^^ stuff);
    }
}

auto formatRange(alias sub, T...)(T args)
{
    class FormatFiber : Fiber
    {
        string front_;
        this()
        {
            super(&run);
            popFront;
        }

        void run()
        {
            sub(this, args);
        }

        void opCall(T)(T t)
        {
            front_ = t.to!string;
            yield;
        }

        void popFront()
        {
            call;
        }

    @property:
        string front()
        {
            return front_;
        }

        bool empty()
        {
            return state != State.HOLD;
        }
    }

    return new FormatFiber;
}

void main()
{
    writeln(formatRange!formatStuff(5));
}
---
Another Idea thoughts?

Reply via email to