Functional programming in Groovy; Besides the curry method :?

Last night I read about a method curry()in Groovy, and I felt a sense of functional programming using this method curry().

As a newbie to Groovy, are there any methods in Groovy that provide functional programming features as a method curry()?

Well, if these methods are explained by a simple example. Thanks in advance.

+3
source share
1 answer

There's also a Closure composition

def plus2  = { it + 2 }
def times3 = { it * 3 }

def composed1 = plus2 << times3
assert composed1(3) == 11

And you can use the Reference operator of the method &to get a reference to the class method, which can then be used with currying or composition.

t

def parseIntRef = Integer.&parseInt

def binaryParse = parseIntRef.rcurry( 2 )
def hexParse    = parseIntRef.rcurry( 16 )

assert binaryParse( '110' ) == 6
assert hexParse(    '0A'  ) == 10

3 curry;

3 , : -)

+4

All Articles