With a condition like
filter(date -> date.isEqual(today) && repository.isDateExist(date))
the term repository.isDateExist(date)
is only evaluated when date
has been proven to be equal to today
, so its outcome is the same as repository.isDateExist(today)
, which doesn’t change during the entire stream operation. Hence, there is no reason to repeatedly check that.
So the preferable variant would be
final boolean todayExist = repository.isDateExist(today);
…
filter(todayExist? today::isEqual: date -> false)
The negation would be
final boolean todayExist = repository.isDateExist(today);
…
filter(todayExist? date -> true: date -> !date.isEqual(today))
though for this you might consider not applying a filter at all when todayExist
is true
.