Java8 Lambdas Hacking to Groovy
Last week, I joined a meetup with Hermes in Nivelles for an online Java 8 Lambda Hacking live stream event with Brian Goetz.
It was about time Java introduced lambda expressions. I’ve been developing in Groovy for a while and the switch to Java is always painful. But it’s much better now.
I took the opportunity to redo the Java 8 lab exercises in Groovy, and I was surprised to see the Java syntax can be expressive. In some more involved cases, I would argue Java is even more expressive than Groovy. Yes, really.
So, is Java grooving now? Check out the code and see for yourself.
// Exercise 8:
// Create a list containing the words, lowercased, in alphabetical order.
@Test
void sortedLowerCase() {
List<String> words = reader
.iterator()
.collect {line -> line.split("\\W+")}
.flatten()
.collect {word -> word.toLowerCase()}
.findAll {word -> !word.isEmpty()}
.sort()
...
}