Groovy, functional programming and the curry method
I'm sure you have heard of functional programming, at least when you
were sill a student (if you are, then you're probably digging into it).
The Groovy language, built on top of Java, provides means of dealing with functional programming. Moreover, it offers a curry method which allows powerful recursion mechanisms.
For example, in maths, you'll want to define the sum function of a list
as the sum of the first element and the (recursive) sum of the rest of
the list. Going further, you'll want to define a meta function which
defines the behaviour of the sum method :
f(x1, x2, ...) = f(x1, f(x2, ...))
That's currying. Here's a basic example which demonstrates this
feature in Groovy. First, let's define a reduce closure which takes as
the first argument the function to be applied on the list of arguments :
Read full article here
Read the full article here
|