A very similar method extraction approach can be applied to Consumer actions, as in the following:
.doOnError(error -> {
Toast.makeText(this, "We couldn't reach internet - falling back to
local data",
Toast.LENGTH_SHORT)
.show();
})
Here, the error handling code can be extracted with a method:
showToastErrorNotification()
So, the line becomes this:
.doOnError(showToastErrorNotification())
Also, the method itself contains this:
@NonNull
private Consumer<Throwable> showToastErrorNotification() {
return error -> {
Toast.makeText(this, "We couldn't reach internet - falling
back to local data",
Toast.LENGTH_SHORT)
.show();
};
}
This way, the actions (consumers) become more descriptive and take less space in the flow itself.