It might not seem very useful to be able to delete keys from an event or event-stream, but if you filter event-streams, it is sometimes useful to unset a key. For example, if \freq
is set “upstream” in an event-stream chain any setting of \degree
etc. downstream will be ineffective when the Event is played (with the default Event.play machinery).
Obviously you can delete a key using a Prout or Pfunc. But requires an extra filtering step (or dropping Pbind[s] and “doing everything” in something else Prouts, Pxfade or a similar event-merging framework [with a suitable notion of merges, basically at least left- or inner joins supported, i.e. Dictionary.blend(fill: false)
in SC’s “terminology”])
But, unless I’m mistaken, there doesn’t seem to be a way to delete a key from within a Pbind, because the first nil on any key ends the whole stream produced by Pbind, i.e.
Pseq([2, nil, 3]).asStream.nextN(3,()) // -> [ 2, nil, 3 ]
Pbind(\foo, Pseq([2, nil, 3]), \bar, 5).asStream.nextN(3, ())
// -> [ ( 'bar': 5, 'foo': 2 ), nil, nil ]
// not really deleting, but tolerates nils as key values:
(Prout({|ev| var fs = Pseq([2, nil, 3]).asStream;
loop { ev = (foo: fs.next, bar: 5).next(ev).yield } }).asStream.nextN(3, ()))
// -> [ ( 'bar': 5, 'foo': 2 ), ( 'bar': 5 ), ( 'bar': 5, 'foo': 3 ) ]
// something that actually deletes from an "upstream"
(Pfunc {|ev| if(ev.foo == 0) {ev.foo = nil}; ev } <>
Pbind(\foo, Pseq([2, 0, 3]), \bar, 5)).asStream.nextN(3, ())
Deleting a key from all events of a stream could be somewhat simpler with Pnaryop(\put, ...
but Pnaryop also ends on nil for any arg:
p = Pbind(\foo, Pseq([2, 0, 3]), \bar, 5);
Pnaryop(\put, p, [\bar, 7]).asStream.nextN(3, ()) // ok, replaces each bar
Pnaryop(\put, p, [\bar, nil]).asStream.nextN(3, ()) // -> []
So has anyone run into this need, and what is/was your approach when you want to do this in the most concise way, i.e. delete a key but still mostly stick with Pbinds? E.g. has anyone (already) implemented a Pbind derivative that supports deleting keys in some concise syntax?