Implement RxJava-like reduce.