GithubHelp home page GithubHelp logo

Comments (4)

TheDeadOne avatar TheDeadOne commented on June 9, 2024 1

Maybe I misunderstood something, but I get an error

cannot find symbol
  symbol:   method addRule(com.deliveredtechnologies.rulebook.model.Rule<com.example.models.SomeClass,java.lang.String>)
  location: class com.deliveredtechnologies.rulebook.lang.RuleBookWithResultTypeBuilder<java.lang.String>

when I try to compile this example without commenting out the line

RuleBook<String> rules = RuleBookBuilder.create()
    .withResultType(String.class)
    //.withDefaultResult("default")
    .addRule(RuleBuilder.create(GoldenRule.class, RuleChainActionType.ERROR_ON_FAILURE)
      .withFactType(SomeClass.class)
      .withResultType(String.class)
      .when(facts -> SomeState.FOO.equals(facts.getOne().getState()))
      .then((facts, result) -> result.setValue("first"))
      .stop()
      .build())
    .addRule(rule -> rule.withFactType(AnotherClass.class)
      .when(facts -> AnotherState.BAR.equals(facts.getValue("another").getState()))
      .then((facts, result) -> result.setValue("second")))
    .build();

NameValueReferableMap<Object> facts = new FactMap<>();
facts.setValue("some", new SomeClass());
facts.setValue("another", new AnotherClass());
rules.run(facts);

I don't need the default. How to get rid of it?

from rulebook.

TheDeadOne avatar TheDeadOne commented on June 9, 2024 1

Yes, I want to have an empty Optional if no rules executed and no default defined, otherwise Optional of result or a default value if it was defined.

from rulebook.

Clayton7510 avatar Clayton7510 commented on June 9, 2024

withDefault is not mandatory. Having a result was always optional.
But if you do have a result and no rules are executed then you would get the default result if you had one.

Do you think it should behave differently?

from rulebook.

Clayton7510 avatar Clayton7510 commented on June 9, 2024

Ah, so if you have a result, then yes, you need to specify a default value. However, there is no requirement for you to have a result. So, perhaps it was I who misunderstood. But am I correct in understanding now that you want to have a result, but no default result?

Presently, that is not something that's possible without a little trickery, like .withDefaultResult(null) or .withDefaultResult(() -> null), with the latter only supported in the 0.12-SNAPSHOT. But maybe it could be a feature add? I'll tag it as an enhancement request and let's see if we can make that happen.

from rulebook.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.