May 11, 2015

Lambdas in Spark: now you're talking!

In a previous article, I tried to figure out what the hell lambdas could be good for in Java. Short version: nice, but not compelling (mostly because of my silly example).

But lo and behold, ye of little faith. The Good (?) Lord of Functional Programming has inspired another much better example in me.

Take a look at this simple Spark program. Nothing fancy, just building key/value pairs from a text file :

In the pre-lambda world, you would build key/value pairs like this:
  "WTF?!" I hear you say and yes, I'd have to agree. This is pretty hard to read and definitely not Java at its finest.

Here's the lamba version:

Do you see the light now? Oh c'mon, just a little bit? ;)

Till next time, keep codin'.

No comments:

Post a Comment