I want use groovy findAll
with my param to filtering closure
filterClosure = { it, param ->
it.getParam == param
}
How can I now call this closure in findAll? Like below?
myColl = someColl.findAll(filterClosure ??? )
Assuming your collection was a list, you could use curry to populate the extra 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 code above, the filterClosure "it" will be assigned what is passed to curry as a parameter and "param" is passed a collection item from findAll. This wouldn't work for a Map collection since findAll for it takes a closure with either one or two parameters.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With