private static <T> Observable<Boolean> commitOrRollbackOnCompleteTransformerIfAtLeastOneValue( final boolean isCommit, final Database db, Observable<T> source) { CountingAction<T> counter = RxUtil.counter(); Observable<Boolean> commit = counter // get count .count() // greater than zero or empty .filter(greaterThanZero()) // commit if at least one value .compose(db.commitOrRollback_(isCommit)); return Observable // concatenate .concat(source // count emissions .doOnNext(counter) // ignore emissions .ignoreElements() // cast the empty sequence to type Boolean .cast(Boolean.class), // concat with commit commit); }