Question for y'all: Is there an operator similar t...
# rx
a
Question for y'all: Is there an operator similar to
combineLatest
but that emits as soon as any of the combined streams have a value? Right now it appears that
combineLatest
will only emit once all of the streams have a value, and will then emit each time one of the streams is updated.
b
Good question. I’ve been wondering this also
a
There's an interesting question of what the types of that would be. Since you can't have
null
values in a stream, you'd need to represent both values as an optional or something along those lines
b
For each of the observables, I wonder if you could have them emit Optional.None, then perform their operation where they eventually return Optional(value)
a
yeah exactly
except as far as I can tell Kotlin doesn't have a real
Optional
type
(could easily be constructed though)
b
We ended up making our own at my company. Optional.None and Optional.Some with easy functions to call them, optional(value).
a
makes sense!
b
Copy code
private fun s() {
        Observable.combineLatest(
                Observable.just(optional(1), optional(2)).startWith(Optional.None),
                Observable.just(optional("a", optional("b"))).startWith(Optional.None),
                BiFunction { ints: Optional<Int>, strings: Optional<String> -> 
                    TODO()
                }
        )
Doesn’t seem to be any errors here. Just doesn’t look pretty. And there is also the useless 1st case where everything is Optional.None. Not sure you want a filter that is checking every time something is emitted
a
Yeah I'm building basically the same thing now but with `Pair`s that are really `Either`s...
b
I keep trying to present to my manager a proper use-case for Either. However, every time a sealed class seems to be the better option
a
I mean I think a sealed class of size two is an either
just without being a monad
which I guess makes it not an either but that's pedantic
u
startWith default values
and then map em to null in the combiner function
or leave em default, whatever you want