Groovy findAll 闭包参数
我想使用 groovy findAll
和我的参数来过滤闭包
filterClosure = { it, param ->
it.getParam == param
}
现在我如何在 findAll 中调用这个闭包?像下面这样?
myColl = someColl.findAll(filterClosure ??? )
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 ??? )
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设你的集合是一个列表,你可以使用 curry 用你的对象填充额外的闭包参数:
在上面的代码中,filterClosure“it”将被分配传递给 curry 作为参数的内容,而“param”将被传递一个集合来自 findAll 的项目。这对于 Map 集合不起作用,因为 findAll 需要一个带有一个或两个参数的闭包。
Assuming your collection was a list, you could use curry to populate the extra closure parameter with your object:
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.