Last active
December 18, 2020 17:32
-
-
Save joost-de-vries/c761e680ac403cf7c0ea49a5cc7c448e to your computer and use it in GitHub Desktop.
"Functional programming"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FunctionalProgramming { | |
private static <T> CheckoutModel<Optional<T>> oldHandleObservable(Observable<T> observable, RegisterFailed attempt) { | |
final Set<ChkNotificationMessage> errorMessages = new HashSet<>(); | |
Optional<T> optional = observable | |
.doOnError(throwable -> errorMessages.addAll(mapChkAdapterExceptions(throwable, attempt))) | |
.onErrorResumeNext(Observable.empty()) | |
.map(Optional::of) | |
.defaultIfEmpty(Optional.empty()) | |
.toBlocking() | |
.single(); | |
optional.ifPresent(it -> errorMessages.addAll(getMessages(it))); | |
return new CheckoutModel<>(optional, errorMessages); | |
} | |
private static <T> Observable<CheckoutModel<Optional<T>>> handleObservable(Observable<T> observable, RegisterFailed attempt) { | |
return observable | |
.map(it -> new CheckoutModel<>(Optional.of(it), getMessages(it))) | |
.onErrorResumeNext(this::handleRedirect) // throw redirect exception | |
.onErrorResumeNext(it -> handleOtherThanRedirect(it, attempt)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment