- yield: pass a value out of a Routine as a return to 'next'.
- embedInStream: if the reciever is another stream itself, return the next value of that stream until it ends (returns nil), then move on to the next 'yield' or 'embedInStream' within the Routine.
a = Routine.new({
Routine.new({
1.yield;
2.yield;
}).embedInStream;
\a.yield;
\b.yield;
Pseq([1234.5], 2).embedInStream
});
20.do({ a.next.postln });
here is an example that shows how an inval is passed into the stream:
f = Prout({ arg inval;
loop({
inval = Prout({ arg in;
in = in.put(in.size.rand, 3).yield // yield returns the new inval
}).embedInStream(inval) // embedInStream also returns the new inval
})
});
e = f.asStream;
5.do({ e.next([0,0,0,0,0,0]).postln; });
This means that the array that is passed in is modified further and further.
Usually an Event is passed as inval, often a copy of the Event.default - if one uses an EventStream, the default event is copied each time it is evaluated.
This copy is not a deep copy of the event, it contains the same elements
as the original. As a result, any event that is contained in the event is identical:
e = Event.new; x = Event.new; e.put(\subevent, x); f = e.copy; e[\subevent] === f[\subevent]; // returns true
As a result, the parent and proto fields of an event, which are used for lookup
if a key has no match, are identical.
Event.default.parent === Event.default.parent; // returns true
this makes EventStreams more efficient and allows referential changes that are transparently passed to children.