1 // These Streams are instantiated by math operations on other Streams
3 UnaryOpStream : Stream {
6 *new { arg operator, a;
7 ^super.newCopyArgs(operator, a)
12 if (vala.isNil, { ^nil },{ ^vala.perform(operator); });
15 storeOn { arg stream; stream <<< a << "." << operator }
19 BinaryOpStream : Stream {
20 var >operator, >a, >b;
22 *new { arg operator, a, b;
23 ^super.newCopyArgs(operator, a, b)
28 if (vala.isNil, { ^nil });
30 if (valb.isNil, { ^nil });
31 ^vala.perform(operator, valb);
33 reset { a.reset; b.reset }
36 stream << "(" <<< a << " " << operator.asBinOpString << " " <<< b << ")"
41 BinaryOpXStream : Stream {
42 var operator, a, b, vala;
44 *new { arg operator, a, b;
45 ^super.newCopyArgs(operator, a, b)
51 if (vala.isNil) { ^nil };
53 if (valb.isNil, { ^nil });
58 if (vala.isNil) { ^nil };
61 if (valb.isNil) { ^nil };
64 ^vala.perform(operator, valb);
66 reset { vala = nil; a.reset; b.reset }
68 stream << "(" <<< a << " " << operator.asBinOpString;
70 stream << " " <<< b << ")"
76 NAryOpStream : Stream {
77 var >operator, >a, arglist;
80 *new { arg operator, a, arglist;
81 ^super.newCopyArgs(operator, a).arglist_(arglist)
85 isNumeric = list.every({ arg item; item.isNumber or: {item.class === Symbol} }); arglist = list;
90 if (vala.isNil, { ^nil });
91 values = if (isNumeric) { arglist } {
92 arglist.collect({ arg item; var res;
93 res = item.next(inval);
94 if(res.isNil) { ^nil };
98 ^vala.performList(operator, values);
100 reset { a.reset; arglist.do({ arg item; item.reset }) }
102 storeOn { arg stream; stream <<< a << "." << operator << "(" <<<* arglist << ")" }