Use concatMapSingle
and mapOptional
to get to the present values:
Observable<Single<Optional<MonetaryAmount>>> amounts =
Observable.fromArray(first, second);
amounts.concatMapSingle(v -> v)
.mapOptional(v -> v) // RxJava 3
.reduce(MonetaryAmount::sum)
;
For RxJava 2, use a filter+map combo:
.filter(Optional::isPresent)
.map(Optional::get)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…