Is there a way to use Optional.orElse in eval?

Viewed 50

I have a function that returns Optional that I want to use in drools eval, e.g.

rule "some rule"
  when
    eval(func().orElse(1.0) > 0.0)
  then
    ....
end

where func() has return type being Optional<Double>. The above is giving me compile error because of orElse. Is there any workaround? Thanks!

1 Answers

Avoid using eval.

Assign the function call's result to a Double and do the comparison there. Something like...

Double( this > 0.0 ) from func().orElse(1.0)

Drools support for Java built-ins and newer functionality (Java 8+) has been hit-or-miss in DRL in my experience, especially with older Drools. If this all doesn't work, your best bet might be to write a method that will wrap the func().orElse(...) and resolve to a simple Double and use that instead.

Related