Plimitsum : Pconst

Plimitsum embeds values from the given pattern into the stream until the sum of the output values exceeds the given threshold. Then the pattern terminates without returning the last value, ensuring that the total of all the output values will always be less than or equal to the threshold.

This is different from Pconst, which outputs a final value when the threshold is crossed so that the total value is exactly equal to the desired sum.

*new(sum, pattern, tolerance)

Example:

p = Plimitsum(10.0, Pwhite(0.5, 1.5, inf)).asStream;

q = p.nextN(30);

q.reject(_.isNil).sum

// compare to Pconst, whose sum should be exactly 10.0

p = Pconst(10.0, Pwhite(0.5, 1.5, inf)).asStream;

q = p.nextN(30);

q.reject(_.isNil).sum