Interface Yielder<T>

  • All Superinterfaces:
    AutoCloseable, Closeable
    All Known Implementing Classes:
    ExecuteWhenDoneYielder

    public interface Yielder<T>
    extends Closeable
    A Yielder is an object that tries to act like the yield() command/continuations in other languages. It's not necessarily good at this job, but it works. I think. Essentially, you can think of a Yielder as a linked list of items where the Yielder gives you access to the current head via get() and it will give you another Yielder representing the next item in the chain via next(). When using a yielder object, a call to yield() on the yielding accumulator will result in a new Yielder being returned whose get() method will return the return value of the accumulator from the call that called yield(). When a call to next() exhausts the underlying data stream without having a yield() call, various implementations of Sequences and Yielders assume that they will receive a Yielder where isDone() is true and get() will return the accumulated value up until that point. Once next is called, there is no guarantee and no requirement that references to old Yielder objects will continue to obey the contract. Yielders are Closeable and *must* be closed in order to prevent resource leaks. Once close() is called, the behavior of the whole chain of Yielders is undefined.
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      T get()
      Gets the object currently held by this Yielder.
      boolean isDone()
      Returns true if this is the last Yielder in the chain.
      Yielder<T> next​(T initValue)
      Gets the next Yielder in the chain.
    • Method Detail

      • get

        T get()
        Gets the object currently held by this Yielder. Can be called multiple times as long as next() is not called. Once next() is called on this Yielder object, all further operations on this object are undefined.
        Returns:
        the currently yielded object, null if done
      • next

        Yielder<T> next​(T initValue)
        Gets the next Yielder in the chain. The argument is used as the accumulator value to pass along to start the accumulation until the next yield() call or iteration completes. Once next() is called on this Yielder object, all further operations on this object are undefined.
        Parameters:
        initValue - the initial value to pass along to start the accumulation until the next yield() call or iteration completes.
        Returns:
        the next Yielder in the chain, or undefined if done
      • isDone

        boolean isDone()
        Returns true if this is the last Yielder in the chain. Review the class level javadoc for an understanding of the contract for other methods when isDone() is true. Once next() is called on this Yielder object, all further operations on this object are undefined.
        Returns:
        true if this is the last Yielder in the chain, false otherwise