question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

FAQ translation of RxJS' withLatestFrom not preserving semantics

See original GitHub issue

The 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:closed
  • Created 7 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
wclrcommented, Aug 2, 2016

I think withLastestFrom should be properly implemented as extra operator

0reactions
staltzcommented, Aug 20, 2016

Issue #102 is for implementing withLatestFrom as an extra operator, so I think we can close this one.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found