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.

flatZip or call it however you want...

See original GitHub issue

Hi everybody,

Lately I have noticed that from time to time I have the following use case:

  • Im zipping many observables by using Observable.zip
  • Some values are actually not interesting from my point of view (and I can know that only during the zipping when I have all the values at hand) so I need to have some value that will represent those unwanted result - usually I use null
  • Right after Observable.zip I have a Observable.filter where Im filtering out all the null s so only the correct values are propagated further

I think that pretty neat solution would be to have a version of Observable.zip method (it can be called completely diffrent) that is workin like zip but accepts function that returns Observable. Thanks to that in such a case as described above we could simply return Observable.empty() and could skip the filtering step.

What do you think about it ?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:1
  • Comments:15 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
tobilarscheidcommented, Dec 6, 2017

I like the idea - I think this is commonly useful and vote for reopening!

2reactions
exicommented, Sep 25, 2018

I would like to argue for a flatZip as well.

Using an Array only works if all components have the same type.

Using my own static method also seems very clunky since it breaks the fluid style of RxJava call chains.

A very common use-case for us is:

Single<Integer> iSingle = fetchInteger();
Single<Float> fSingle = fetchFloat();
Single<String> sSingle = fetchString();
Single.zip(iSingle, fSingle, sSingle, (i, f, s) -> fetchMoreData(i, f, s));

The problem here is that fetchMoreData also returns a Single which is currently not really easy to handle if i don’t want to end up with a Single<Single<Data>>.

So i’m stuck with:

Single<Integer> iSingle = fetchInteger();
Single<Float> fSingle = fetchFloat();
Single<String> sSingle = fetchString();
Single.zip(iSingle, fSingle, sSingle, MyCustomContainer::create)
  .flatMap(container -> fetchMoreData(container.getI(), container.getF(), container.getS());

Which is also very ugly and required me to have some custom tuple type just to be able to return some async value.

Read more comments on GitHub >

github_iconTop Results From Across the Web

java - flatZip in RxJava - Stack Overflow
What I'd like to be able to do is: final Observable<M> result = Observable.flatZip(obs1, obs2, transformFunc);. What's the cleanest way to do ...
Read more >
Flat Zip Creation - Apple Support Communities
Basically, I want to know how to select many photos and compress all of them into a zip file but then when one...
Read more >
How can I generate a flat ZIP with no folders hierarchy?
I wrote a quick script on .net to download all images scaled down to 100px, I'm able to download the zip, but I...
Read more >
Flat Zip Wallet - Etsy
Check out our flat zip wallet selection for the very best in unique or custom, handmade pieces from our shops.
Read more >
Longchamp Le Foulonne Flat Zip Crossbody | Bloomingdale's
Shop Le Foulonne Flat Zip Crossbody online at Bloomingdales.com. Look chic around the clock with this leather crossbody from Longchamp in an understated, ......
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