Say, I want to make an Observable in RxJava, which has a feedback coupling like on the image below.
I've managed to achieve that with the use of subjects, like this:
// Observable<Integer> source = Observable.range(0, 6); public Observable<Integer> getFeedbackSum(Observable<Integer> source) { UnicastSubject<Integer> feedback = UnicastSubject.create(); Observable<Integer> feedbackSum = Observable.zip(source, feedback.startWith(0), Pair::create) .map(pair -> pair.first + pair.second); feedbackSum.subscribe(feedback); return feedbackSum; } It looks rather ugly. Is there a better way?

scan.