Morgan-Stanley / morphir-elm / Morphir.SDK.Rule

This module supports defining business logic as a set of rules. You can think of it as a functional rules engine. The logic is built up of rules that are composed into rule sets. In traditional rules engines these rule sets can be executed in a variety of ways that can yield different results. Morphir prefers predictability over flexibility so we only support sequential execution. While this might sound limiting it greatly improves readability and enforces modelers to break up large rule sets into smaller targeted ones.


type alias Rule a b =
a -> Maybe b

Type that represents a single rule. A rule is a function that is only applicable on certain inputs. In other words it's a partial-function. Since Elm/Morphir only supports total functions it is represented as a function that returns an optional value. When the function is applicable it will return Just b otherwise Nothing.

chain : List (Rule a b) -> a -> Maybe b

Chain a list of rules into a single rule. Rules are evaluated sequentially in the order they were supplied and the first rule that matches will be applied.

myChain =
    chain
        [ \a -> Nothing -- A rule that never matches
        , \a -> Just a -- A rule that always matches and returns the original value
        ]

myChain 42 == Just 42

any : a -> Basics.Bool

Simply returns true for any input. Use as a wildcard in a decision table.

is : a -> a -> Basics.Bool

Returns True only if the second argument is equal to the first. Use in a decision table for exact match.

anyOf : List a -> a -> Basics.Bool

Returns True only if the second argument can be found in the list specified in the first argument. Use in a decision table to match when a value is in a predefined set.

noneOf : List a -> a -> Basics.Bool

Returns True only if the second argument cannot be found in the list specified in the first argument. Use in a decision table to match when a value is not in a predefined set.