These are chat archives for ReactiveX/RxJava

20th
Oct 2015
David Stemmer
@weefbellington
Oct 20 2015 13:58
looking for suggestions: when you write a custom Observable, Operator or Transformer, where do they live?
Simon Baslé
@simonbasle
Oct 20 2015 14:01
in a project using Rx you mean?
so far in our project we've either implemented ActionX or FuncX, always close to the using code because generally very specific... not an awful lot of Observables/Operators/Transformers so far but the very few live in a com.company.project.util kind of namespace
although com.company.project.rx would also make sense I guess
David Stemmer
@weefbellington
Oct 20 2015 14:11
Our code uses a fair amount of transformers and a couple of operators and custom observables. I've come up with a few adhoc conventions myself:
  1. if it's a mapping function that just extracts data from a data object, or a predicate related to the data, put the function as a final field on the data object itself: api.getResponse().filter(Response.HAS_ERROR).map(Response.ERROR)
  2. I try to avoid new MyTransformer(), new MyAction() calls everywhere in my code and instead create factory methods. So I might have a RxLogger class that has actions related to logging, which you would call like stringObservable.doOnNext(rxLogger.logDebug)
  3. there's a big class that's just called Operators which contains factory methods for creating custom Transformers, Operators, Functions and Actions. Most of these are generic and aren't associated with any particular data type. I'm trying to get rid of this class but am struggling to come up with a good alternative
(a lot of this could probably mitigated if I could use lambdas, but we're currently using Android without retrolambda)
Simon Baslé
@simonbasle
Oct 20 2015 14:15
  1. and 2. sound sane to me, 3. I'd probably split it and put all of it into a util.rx package with as many classes as you have generic Operators, Transformers, Func and Action... but that's just me :)
Rudi Grinberg
@rgrinberg
Oct 20 2015 20:25
quick question, suppose I’m handling a click with an observable (i’m using rxjava but i don’t think it matters), i want a subsbcription to fire on every click and get the value of another observable in that subscription. how would i accomplish that?
i think i need withLatestFrom
Dorus
@Dorus
Oct 20 2015 21:31
Sample
David Stemmer
@weefbellington
Oct 20 2015 22:00
withLatestFrom looks right to me, but I haven't used it much
Dorus
@Dorus
Oct 20 2015 22:06
The difference between sample and withLatestFrom is that sample does not combine the sequences, and does not emit duplicate values from the other subscription if it did not fire since the last click. This might or might not be what you want.
David Stemmer
@weefbellington
Oct 20 2015 22:20
to me, the use case that seems pretty natural for withLatestFrom is:
  1. I have a stream of button click events (an Observable<View>)
  2. I have a data stream (an Observable<Data>)
  3. every time the button is clicked, I want to emit the most recent data:clickStream.withLatestFrom(dataStream, (left, right) -> right).subscribe(parseData)
@Dorus ^^ is that a sane thing to do...?
Dorus
@Dorus
Oct 20 2015 22:23
Looks right. I might name left and right click and data or even _ instead of click (.net style). I'm used to .net and the poor thing doesnt even have a withLatestFrom, so i was stuck with Sample.