The OpenD Programming Language

yield

Yields a value of type T to the caller of the currently executing generator.

  1. void yield()
  2. void yield(T value)
  3. void yield(T value)
    void
    yield
    (
    T
    )
    ()

Parameters

value T

The value to yield.

Examples

import std.range;

InputRange!int myIota = iota(10).inputRangeObject;

myIota.popFront();
myIota.popFront();
assert(myIota.moveFront == 2);
assert(myIota.front == 2);
myIota.popFront();
assert(myIota.front == 3);

//can be assigned to std.range.interfaces.InputRange directly
myIota = new Generator!int(
{
    foreach (i; 0 .. 10) yield(i);
});

myIota.popFront();
myIota.popFront();
assert(myIota.moveFront == 2);
assert(myIota.front == 2);
myIota.popFront();
assert(myIota.front == 3);

size_t[2] counter = [0, 0];
foreach (i, unused; myIota) counter[] += [1, i];

assert(myIota.empty);
assert(counter == [7, 21]);

Meta