【发布时间】:2014-12-26 20:56:32
【问题描述】:
我有一个闭包:
def Boolean check(String name, String value, Context c){
c.name.equalsIgnoreCase(value);
}
有获取闭包的get方法:
def getClosure() {
check
}
我正在尝试获取两个呼叫的逻辑析取(名称可能是“狗”或“猫”):
c1 = check.curry("name", "Dog");
c2 = check.curry("name", "Cat");
c3 = c1 || c2; /*Could this closure be created?*/
Context ctx = new Context();
c3.call(ctx);
我的问题是有没有办法创建一个 c3 闭包?
谢谢!
【问题讨论】:
-
你不能使用番石榴谓词吗?当您正在缩减为单个参数闭包时,它们应该只使用 groovy
as干净地映射 -
c3.call(ctx)应该返回['Dog', 'Cat']、['Dog']或['Cat']?