Pihentagy
06/19/2024, 9:13 AMPihentagy
06/19/2024, 9:16 AMJoffrey
06/19/2024, 12:30 PMRule
class implementation doesn't bring anything meaningful to the table, given that the 2 factory functions are so vastly different.
The whole code could be reduced to just a Rule
interface with abstract fire()
and 2 different factory functions providing the boolean approach or the object-based onePihentagy
06/19/2024, 12:32 PMPihentagy
06/19/2024, 12:35 PMval rule1: Rule<Int, Void>;
val rule2: Rule<String, Whatever>;
val ruleset = RuleSet(rule1, rule2, ...);
ruleset.fireAllRulesFor("string");
Joffrey
06/19/2024, 12:38 PMruleset.fireAllRulesFor("string");I think an extremely similar question was posted recently 🤔
Joffrey
06/19/2024, 12:45 PMPihentagy
06/19/2024, 12:47 PMJoffrey
06/19/2024, 12:47 PMfire
could be passed to the Rule
class to make it more general, no need for breaking it down into partsJoffrey
06/19/2024, 12:48 PMJoffrey
06/19/2024, 12:49 PMif (!clazz.isInstance(arg)) return false
is redundant. This class cannot be called with an arg
that is not a T
, unless you mess with the compiler, but in that case this is not the place to put this check. In our original conversation about fireAllRulesFor
, this check was in the RuleSet
(not the Rule
) for this reason.Pihentagy
06/19/2024, 12:49 PMPihentagy
06/19/2024, 12:50 PMJoffrey
06/19/2024, 12:53 PMPihentagy
06/19/2024, 12:58 PMJoffrey
06/19/2024, 1:44 PMPihentagy
06/19/2024, 1:45 PMJoffrey
06/19/2024, 1:47 PMJoffrey
06/19/2024, 1:48 PMPihentagy
06/19/2024, 1:56 PMval rule = Rule.compute<Int, _>("int rule", obj = { if (this < 0) this * 2 else null })
something like
val rule = Rule.compute("int rule", obj = Int.{ if (this < 0) this * 2 else null })
Pihentagy
06/19/2024, 1:56 PM