.flatMap(new Func1<Integer, Observable<ObserveResponse>>() {
@Override
public Observable<ObserveResponse> call(Integer replicas) {
List<Observable<ObserveResponse>> obs = new ArrayList<Observable<ObserveResponse>>();
if (persistTo != PersistTo.NONE) {
obs.add(core.<ObserveResponse>send(new ObserveRequest(id, cas, true, (short) 0, bucket)));
}
if (persistTo.touchesReplica() || replicateTo.touchesReplica()) {
if (replicas >= 1) {
obs.add(core.<ObserveResponse>send(new ObserveRequest(id, cas, false, (short) 1, bucket)));
}
if (replicas >= 2) {
obs.add(core.<ObserveResponse>send(new ObserveRequest(id, cas, false, (short) 2, bucket)));
}
if (replicas == 3) {
obs.add(core.<ObserveResponse>send(new ObserveRequest(id, cas, false, (short) 3, bucket)));
}
}
return Observable.merge(obs);
}
});