<@U0BRK9HC5> Are you sure you can't `map` the `Beh...
# rx
l
@gildor Are you sure you can't
map
the
BehaviorSubject
? Not trying to argue, but the above does allow values to be pushed into it? I'm not quite sure what you mean by the alternative solution. The general goal is to have this
Subject
observer listen to values of this
List
, and emit
filtered
versions of the
List
. New to Rx, so maybe I have the structure of the way this should work setup incorrectly. It was my understanding that
Subjects
act as both
Observer
and
Observable
.
g
Of course you can map Behavior subject, but result of this mapping will be Observable, not a different behavior subject. Do you understand why you current solution is wrong? You just do nothing with mapped subject. Try to fix it and you will get what I mean. You can map, but you must cache both objects: subject and mapped Observable I understand what do you want to achieve, your code in second case just wrong because you don't use result of invocation
Alternative solution: filter lists before pushing them to subject instead of mapping them later
l
I understand what you're saying, but it seems like the easy solution is to just do this:
Copy code
val observable: Observable<List<Int>> by lazy {
        filterSubject.map{
            it -> it.filter(filter)
        }
    }
And now we're retaining the
Observable
, not creating more than one, and still accomplishing the goal.
g
Yes, yes, you right, just cache both, subject and Observable
m
you should make it a function, and return a new instance everytime you want observe something
like this:
Copy code
override fun observeBandConnState(emmitFirst: Boolean): Observable<Boolean> {
        return protocolCallbackImpl.bandConnState
            .startWith(emmitFirst, isAvailable)
            .distinctUntilChanged()
            .observeOn(AndroidSchedulers.mainThread())
    }
bandConnState is a Subject