Reactive-Extensions / RxJS

The Reactive Extensions for JavaScript
http://reactivex.io
Other
19.48k stars 2.1k forks source link

Add flatMapFirst to RxJS core #732

Closed boccob closed 9 years ago

boccob commented 9 years ago

Does it make sense to add flatMapFirst that is analog of flatMap which adds new observable only if the previous one ended? It already exists in bacon - flatMapFirst And in kefir - flatMapFirst. And there is no obvious way to do the same in RxJS without creating new function and without adding new variables with current state of mapped observable.

I already added it to a project on which I work at the moment and I can do a pull request.

urmastalimaa commented 9 years ago

How would flatMapFirst be different from concatMap?

boccob commented 9 years ago

With flatMapFirst value from initial observable will not be mapped to result observable if the previous one is not ended. Example:

Source:     ------1----2----3x
Spawned 1:        -------1x
Spawned 2:             -------2x
Spawned 3:                  -------3x
Result:     -------------1---------3x

And Spawned 2 will not be created because Spawned 1 is not completed when 2 appeared in Source.

Actually I had case when I needed to create new request for each click on element. And I didn't want to create new requests while I didn't get response. Simplified example here: http://jsbin.com/noquqa/2/edit?js,console,output

bman654 commented 9 years ago

It already exists (undocumented) as exclusive and exclusiveMap.

boccob commented 9 years ago

Thank you! Does it make sense to add documentation and tests for it?

boccob commented 9 years ago

Actually I found that there is another issue about documentation for this methods. So I'm closing this issue.