It is not necessary to return a new lambda every time with the method calls--in lots of cases, we can use method references directly.
We have used this earlier:
.doOnError(showToastErrorNotification())
Instead, we could have as well created a method:
private void showToastErrorNotificationMethod(Throwable error) {
Toast.makeText(this, "We couldn't reach internet - falling back
to local data",
Toast.LENGTH_SHORT)
.show();
}
Then, we can replace the .filter() with this:
.doOnError(this::showToastErrorNotificationMethod)
There is very little difference between the two approaches, and it boils down to the personal preference. Usually, calling method, such as in the following case, gives more flexibility to do additional stuff inside the showToastErrorNotification() call (or the so-called lambda factory):
.doOnError(showToastErrorNotification())
However, the approach that uses the method reference avoids needlessly creating new lambdas every time:
.doOnError(this::showToastErrorNotificationMethod)