@Override public Subscription subscribe(EventObserver<E> observer) { EventSubscriber<E> flattenSubscriber = new EventSubscriber<>(observer); CompositeSubscription subscriptions = new CompositeSubscription(); Subscription streamSub = streamOfStreams .map(stream -> stream.onEvent(flattenSubscriber::onEvent)) .observe(EventObserver.create(subscriptions::add, flattenSubscriber::onCompleted)); subscriptions.add(streamSub); flattenSubscriber.doOnDispose(subscriptions::dispose); return flattenSubscriber; }
@Override public EventSubscriber<T> apply(EventSubscriber<T> childSubscriber) { EventObserver<T> sourceObserver = EventObserver.create( value -> { if (predicate.test(value)) childSubscriber.onEvent(value); }, childSubscriber::onCompleted); return new EventSubscriber<>(sourceObserver); }