-
-
Notifications
You must be signed in to change notification settings - Fork 139
Open
Description
Hey folks!
I found a strange behavior of sampleCombine.
It reproduces in case of: input.compose(sampleCombine(derivedFromInput, independentOfInput)) - only when:
- some
derivedFromInput(or just sameinput) is the first parameter ofsampleCombine - and other parameters are independent of
input.
In such cases other parameters are independent ofinputwill be one step late.
Code to reproduce:
xs.periodic(100)
.take(5)
.compose(all => { // all - independent of values
// squaresAll - independent of values
const squaresAll = all.map(v => v * v).debug('squareAll');
// values - 'derived' from it self
const values = all.debug('values');
// squaresValues - derived from values
const squaresValues = values.map(v => v * v).debug('squareValues');
// [ 0, 0, 0 ] - OK
// [ 2, 4, 2 ] - OK
// [ 3, 9, 3 ] - OK
// [ 4, 16, 4 ] - OK
// return values.compose(sampleCombine(squaresAll, values));
// [ 0, 0, 0 ] - OK
// [ 2, 4, 2 ] - OK
// [ 3, 9, 3 ] - OK
// [ 4, 16, 4 ] - OK
// return values.compose(sampleCombine(squaresValues, values));
// [ 0, 0, 0 ] - OK
// [ 2, 2, 4 ] - OK
// [ 3, 3, 9 ] - OK
// [ 4, 4, 16 ] - OK
// return values.compose(sampleCombine(values, squaresValues));
// [ 0, 0, 0 ] - missed,
// [ 2, 2, 1 ] - incorrect (squaresAll: previous value)
// [ 3, 3, 4 ] - incorrect (squaresAll: previous value)
// [ 4, 4, 9 ] - incorrect (squaresAll: previous value)
// return values.compose(sampleCombine(values, squaresAll));
// [ 0, 0, 0 ] - OK
// [ 1, 1, 1 ] - OK
// [ 2, 2, 4 ] - OK
// [ 3, 3, 9 ] - OK
// [ 4, 4, 16 ] - OK
// return values.compose(sampleCombine(all, squaresAll));
// [ 0, 0, 0 ] - OK
// [ 1, 1, 1 ] - OK
// [ 2, 2, 4 ] - OK
// [ 3, 3, 9 ] - OK
// [ 4, 4, 16 ] - OK
// return values.compose(sampleCombine(all, squaresValues));
// [ 0, 0, 0 ] - OK
// [ 1, 1, 1 ] - OK
// [ 2, 4, 2 ] - OK
// [ 3, 9, 3 ] - OK
// [ 4, 16, 4 ] - OK
// return values.compose(sampleCombine(squaresAll, all));
// [ 0, 0, 0 ] - missed,
// [ 1, 1, 0 ] - incorrect (all: previous value)
// [ 2, 4, 1 ] - incorrect (all: previous value)
// [ 3, 9, 2 ] - incorrect (all: previous value)
// [ 4, 16, 3 ] - incorrect (all: previous value)
// return values.compose(sampleCombine(squaresValues, all));
// [ 0, 0, 0 ] - OK
// [ 1, 1, 1 ] - OK
// [ 2, 4, 4 ] - OK
// [ 3, 9, 9 ] - OK
// [ 4, 16, 16 ] - OK
// return values.compose(sampleCombine(squaresAll, squaresValues));
// [ 0, 0, 0 ] - missed,
// [ 1, 1, 0 ] - incorrect (squaresAll: previous value)
// [ 2, 4, 1 ] - incorrect (squaresAll: previous value)
// [ 3, 9, 4 ] - incorrect (squaresAll: previous value)
// [ 4, 16, 9 ] - incorrect (squaresAll: previous value)
return values.compose(sampleCombine(squaresValues, squaresAll));
})
.addListener(printer());
export const printer = <T = any>(): Listener<T> => ({
next: console.log,
error: console.error,
complete: () => console.log('completed'),
});Metadata
Metadata
Assignees
Labels
No labels