我可以在groovy中结合两个闭包吗?

时间:2014-12-26 20:56:33

标签: groovy closures

我有一个关闭:

def Boolean check(String name, String value, Context c){
   c.name.equalsIgnoreCase(value);
}    

有一个获取闭包的get方法:

def getClosure() {
    check
}

我试图获得两次调用的逻辑分离(名称可能是“Dog”或“Cat”):

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闭包?

谢谢!

1 个答案:

答案 0 :(得分:3)

我不认为Groovy附带了一个组合器用于或者谓词(如果这就是你要问的那个)。您可能需要c3 = { c1(it) || c2(it) }