FAQ translation of RxJS' withLatestFrom not preserving semantics
See original GitHub issueThe following code
import Rx from 'rxjs/Rx';
const s1 = Rx.Observable.interval(1000).take(3);
const s2 = Rx.Observable.interval(100).take(30);
const s3 = s1.withLatestFrom(s2, (v1,v2) => [v1,v2])
s3.subscribe(function (x) { console.log(x) })
outputs
[ 0, 8 ]
[ 1, 18 ]
[ 2, 28 ]
According to FAQ, withLatestFrom
can be expressed in xstream as follows:
import xs from 'xstream'
const s1 = xs.periodic(1000).take(3);
const s2 = xs.periodic(100).take(30);
const s3 = s1.map((v1) => s2.map((v2) => [v1,v2])).flatten();
s3.addListener({
next: x => console.log(x),
error: err => console.error(err),
complete: () => console.log('completed')
})
However, it outputs 30 tuples instead of 3:
[ 0, 0 ]
[ 0, 1 ]
[ 0, 2 ]
[ 0, 3 ]
[ 0, 4 ]
[ 0, 5 ]
[ 0, 6 ]
[ 0, 7 ]
[ 0, 8 ]
[ 1, 9 ]
[ 1, 10 ]
[ 1, 11 ]
[ 1, 12 ]
[ 1, 13 ]
[ 1, 14 ]
[ 1, 15 ]
[ 1, 16 ]
[ 1, 17 ]
[ 1, 18 ]
[ 2, 19 ]
[ 2, 20 ]
[ 2, 21 ]
[ 2, 22 ]
[ 2, 23 ]
[ 2, 24 ]
[ 2, 25 ]
[ 2, 26 ]
[ 2, 27 ]
[ 2, 28 ]
[ 2, 29 ]
completed
Issue Analytics
- State:
- Created 7 years ago
- Comments:9 (3 by maintainers)
Top Results From Across the Web
Implement "withLatestFrom" as an extra operator #102 - GitHub
FAQ translation of RxJS' withLatestFrom not preserving semantics #97 ... staltz changed the title combineLeft aka withLatestFrom Implement ...
Read more >withLatestFrom - RxJS
withLatestFrom combines each value from the source Observable (the instance) with the latest values from the other input Observables only when the source ......
Read more >Why withLatestFrom RxJS method not static? - Stack Overflow
I think a good example is the combineLatest operator that exists as both static and instance method. The order of source Observables to ......
Read more >withLatestFrom - Learn RxJS
If you want the last emission any time a variable number of observables emits, try combinelatest!
Read more >Angular Archives - The Oasis Digital Blog
Think of it as a prototype for an app that shows names as they are translated in various languages (Matthew, Mateo, Matthäus, Матфей,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think
withLastestFrom
should be properly implemented as extra operatorIssue #102 is for implementing withLatestFrom as an extra operator, so I think we can close this one.