I've the following code in Java and would like to port it in Ceylon.
public interface Condition {
Condition FALSE = facts->false;
Boolean evaluate(Fact<?> fact);
default Condition and(Condition other) {
return fact -> this.evaluate(fact) && other.evaluate(fact);
}
}
@Test void test() {
String str = "A String";
Condition a = fact -> !str.empty();
Condition b = fact -> str.contains("tr");
Condition both = a.and(b);
//expect(both(Fact('fact', str)), true);
}
So far I've tried using alias
for the given code
shared alias Condition => Boolean(Fact<out Anything>);
Condition falseCondition = (Fact<out Anything> fact) => false;
shared interface ConditionComposer {
shared formal Boolean eval(Fact<out Anything> fact);
shared default Condition and(Condition other)<--**I want to pass a Condition here for the below to work** {
return (Fact<out Anything> fact) => this.eval(fact) && other.eval(fact);
}
}
I want to pass a Condition
as a parameter to and()
but as the eval()
is part of ConditionComposer
, the return statement won't compile. And how will I write a test case for this in Ceylon?