PbindArrayDefault : Pbind

PbindArrayDefault differs from Pbind in its handling of array items in the key/value pairs.

Consider a Pbind as follows (a bit contrived, but it could happen). Note that the event prototype e contains default values for a, b, c and d.

p = Pbind(

[\a, \b, \c, \d], Pfunc({

var out = Array.newClear(4);

3.do({ out[4.rand] = 10.rand + 1 });

out

})

).asStream;

e = (a: 0, b: 0, c: 0, d: 0);

p.next(e);

( 'c': 3, 'a': 5, 'b': 5 )

( 'd': 5 )

( 'a': 8, 'b': 8, 'd': 5 )

( 'd': 3 )

Some of the defaults are lost because they are overwritten by nil values in the Pfunc result array.

With PbindArrayDefault, nil values in the array will preserve the default values set in the event.

p = PbindArrayDefault(

[\a, \b, \c, \d], Pfunc({

var out = Array.newClear(4);

3.do({ out[4.rand] = 10.rand + 1 });

out

})

).asStream;

p.next(e);

( 'c': 0, 'a': 6, 'b': 0, 'd': 6 )

( 'c': 0, 'a': 3, 'b': 5, 'd': 5 )

( 'c': 0, 'a': 0, 'b': 4, 'd': 3 )

( 'c': 0, 'a': 1, 'b': 2, 'd': 0 )

I will be honest that I'm not sure how useful this is, but it does work.