Hi All!
I'm want use groovy findAll with my param to filtering closure
filterClosure = { it, param ->
it.getParam == param
}
How now i'm can call this closure in findAll? Something lik bellow?
myColl = someColl.findAll(filterClosure ??? )
Hi All!
I'm want use groovy findAll with my param to filtering closure
filterClosure = { it, param ->
it.getParam == param
}
How now i'm can call this closure in findAll? Something lik bellow?
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.