ossgang / ossgang-commons

Apache License 2.0
4 stars 0 forks source link

Observables.combineLatest with different classes #49

Closed andreacalia closed 4 years ago

andreacalia commented 4 years ago

At the moment the combineLatest operators allows only to have single classes as input observables..

Property<String> valueA = property("A");
Property<String> valueB = property("B");

Observables.combineLatest(asList(valueA, valueB), (List<String> values) -> ...);

It would be nice to also be able to support different types...

Property<String> valueA = property("A");
Property<Integer> valueB = property(1);

Observables.combineLatest(asList(valueA, valueB), ...);

To be defined how the API should look like.. for sure there are multiple solution, I'll make a proposal that suits our current project :slightly_smiling_face:

michi42 commented 4 years ago

Hmm, I'm afraid for the most general solution (N observables * M types) we can only use objectes, since Java does not support Variadic (var-args) Generics ...

However, we could provide a few overloaded methods for 2,3,4,... (up to how many?) typed arguments for convenience:

<T1,T2> combineLatest(Observable<T1> o1, Observable<T2> o2, BiConsumer<T1,T2> ...)

These can be type safe - internally they can use the more generic List<Object> functionality ...

andreacalia commented 4 years ago

Exactly :slightly_smiling_face: . I'm trying to implement it as safe as possible for all cases while providing handy typed options in the static methods for the common cases.

michi42 commented 4 years ago

Perfect 🙂