Groovy find All close options

I want to use groovy findAll with my parameter to filter closure

 filterClosure = { it, param -> it.getParam == param } 

How can I call this closure in findAll? How below?

 myColl = someColl.findAll(filterClosure ??? ) 
+7
parameters groovy findall
source share
1 answer

Assuming your collection was a list, you can use curry to populate an additional closure parameter with your object:

 def someColl = ["foo", "bar", "foo", "baz", "foo"] def filterClosure = { it, param -> it.getParam == param } myColl = someColl.findAll(filterClosure.curry([getParam:'foo'])) assert ["foo", "foo", "foo"] == myColl 

In the filterClosure code above, "it" will be assigned to pass curry as a parameter, and "param" to pass the collection item from findAll. This will not work for a map collection, since findAll takes a closure with one or two parameters for it.

+7
source share

All Articles