posted 1 year ago
You're not really using the lambda expressions correctly though. The point of a lambda expression is to pass the function it evaluates to to a higher order function, not to call it directly. Here is a better example:
Without lambda expressions, Python:
With lambda expressions, Python:
As you can see, lambda expressions in Python allow you to define a function inline with the higher order function call. This makes the code slightly less verbose, but the tradeoff is that your code becomes slightly more difficult to read.
Personally, I find that lambda expressions are rarely worth it. I prefer the more readable version where you declare a named function.
In Java, I would declare an isEven() method explicitly, and then pass it as a predicate function to the filter() call by using a method reference: