Patent ID: 7661096

Claim:
A generator compilation system, the system that includes a processor and a computer-readable-storage-medium storing the following components that are executable by the processor: a receiver component that receives a stream, wherein the stream includes a sequence of one or more elements; a type component that determines whether the stream is nested or non-nested by identifying a type of the stream, wherein the stream is non-nested when the type is enumerable, and the stream is nested when the type is stream; an adapter component that enables iteration across the non-nested stream when the stream is determined to be a non-nested stream to produce a state output in accordance with nested stream states, the iteration across the non-nested stream comprising: retrieving an element from the non-nested stream, returning a state value indicating the element is available, producing the element, moving an index to a next element, and terminating the iteration when a return state indicating that all elements in the non-nested stream have been seen and produced; an enumeration component that enables iteration across the nested stream when the stream is determined to be a nested stream by recursively using a stack to produce a flattened stream that enumerates one or more elements, the iteration across the nested stream comprising: pushing the nested stream onto the stack, and making the nested stream as an active stream in the stack; retrieving all the elements in the active stream from the stack, the retrieving all the elements in the active stream comprising: determining whether the retrieved element is a base element or a stream, pushing the received element onto the top of the stack when the retrieved element is a stream, and producing the retrieved element in the flattened stream when the retrieved element is a base element, popping the active stream from the stack when all elements in the active stream are consumed; and a state component that generates a state machine to facilitate efficient iteration through the nested stream by optimizing one or more tail-calls, the optimizing comprising popping a parent stream from the stack when the one or more tail-calls occur, wherein the one or more tail-calls indicating last element of the active stream is a nested stream.