Skip to content

Commit

Permalink
Fix final method - add helper to wrap response to Optional
Browse files Browse the repository at this point in the history
  • Loading branch information
tspoke committed Sep 13, 2017
1 parent 95a84f0 commit 2f12fe0
Showing 1 changed file with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public boolean hasSyncedStore(){
}

@Override
public final Flowable<Optional<List<T>>> getAll(final Filter filter, final SortingMode sortingMode) {
public Flowable<Optional<List<T>>> getAll(final Filter filter, final SortingMode sortingMode) {
List<Flowable<Optional<List<T>>>> flowables = new ArrayList<>();
Flowable<Optional<List<T>>> flowStorage = dao.getAll(filter, sortingMode);

Expand Down Expand Up @@ -591,4 +591,23 @@ public Flowable<Integer> apply(Optional<T> reinsertedItem) throws Exception {
flowables.add(flowStorage);
return Flowable.concat(flowables);
}

/**
* Wrap an object into an flowable optional
*/
public <S> Flowable<Optional<S>> wrapOptional(S obj){
return Flowable.just(Optional.wrap(obj));
}

/**
* Wrap a flowable object into an flowable optional
*/
public <S> Flowable<Optional<S>> wrapOptional(Flowable<S> obj){
return obj.flatMap(new Function<S, Flowable<Optional<S>>>() {
@Override
public Flowable<Optional<S>> apply(S s) throws Exception {
return wrapOptional(s);
}
});
}
}

0 comments on commit 2f12fe0

Please sign in to comment.