Thd Plazy code looks like this
Plazy : Pattern {
var <>func;
*new { arg func;
^super.new.func_(func)
}
//asStream { arg ... args;
// ^func.valueArray(args).asStream
// }
embedInStream { arg inval;
^func.value(inval).embedInStream(inval)
}
storeArgs { ^[func] }
}
The asStream
seems redundant, which is perhaps why it’s commented, but it’s actually useful in one obscure case when you return a Pfunc from Plazy:
(p = Plazy{var arrs = [[1, 2], [3, 4]], apos = 0, ipos = -1;
Pfunc
{ arrs @@ apos @@ (ipos = ipos + 1) }
{ apos = apos + 1 }
})
The issue of most streams “eating” the resets and not passing them down as such due to their Routine
asStream
implementation as been discussed before.
Basically here with Plazy as-is (commented out asStream “special”)
r = p.asStream; // -> a Routine
r.nextN(3); // -> [ 1, 2, 1 ]
r.reset;
r.nextN(3); // -> [ 1, 2, 1 ] (i.e. same)
Whereas what the commented out “special” asStream would do:
r = p.func.value.asStream // -> a FuncStream
r.nextN(3); // -> [ 1, 2, 1 ]
r.reset;
r.nextN(3); // -> [ 4, 3, 4 ]
So the commented out “special” asStream
in Plazy could have some benefits for making Pfuncs work better inside Plazy (and Plazy’s encapsulating the state between calls for Pfuncs seems fairly useful). So are there any downsides to the “special” asStream
in Plazy that’s currently commented out?