flatScan does not work for Properties
semmel opened this issue · comments
Currently you get an error if trying .flatScan
on a Property:
// Error: no arguments supported
Bacon.constant(8).flatScan(100, (acc, x) => Bacon.once(acc + x)).log();
// for EventStreams it's fine:
Bacon.once(8).flatScan(100, (acc, x) => Bacon.once(acc + x)).log()
// 100, 108, <end>
This is because the implementation of this.flatScan(seed, f)
is basically this.flatMapConcat(next => ...).toProperty(seed);
Which fails of course if this
is already a Property.
The problem seems to be that both a Property has a current value, and .flatScan
has too. I cannot tell which should come first.
Perhaps to fix the implementation one could think to introspect this
if being a Property and then "push" seed
before the Properties current value.
However, I'd find it surprising that with a fix .flatScan(y, (acc, x => Bacon.never())
changes the current value of my Property:
// What is expected of
Bacon.constant(8).flatScan(100, Bacon.never);
// 100 ? But where is my 8 ?
// 8 ?
// 8, 100 ?
Bacon.constant(8).flatScan(100, (acc, x) => Bacon.once(acc + x))
// 100, 108 Is this expected?
// 8, 100, 108 ?
I'd say .flatScan
should be just for EventStreams. It would not be a breaking change, since the implementation is broken anyway for Properties, is it?
I concur. Let's make it for EventStreams only.
Actually it's for EventStream only in the docs too.