A global lambda is a global variable. As a global variable is must follow all the same restrictions and scope of any other global variable. This means:
- only can be accessed from the file they are defined in
- cannot see any other global variables
- are not thread safe
Since you cannot pass arguments to Rules DSL Scripts nor get a return value, lambdas are pretty much useless in that context.
There are not, and frankly if you are hoping to use lambdas to simplify your Rules you are probably heading down the wrong path anyway. See Design Pattern: DRY, How Not to Repeat Yourself in Rules DSL for better approaches. Or consider moving to one of the JSR223 supported languages.
No, not possible
Why not use JSR223 and code your rules in Jython, JavaScript, or Groovy instead and keep everything local?
Or if you want something easier to use configure NodeRed as your Rule engine.
Or, as illustrated in the DP I linked to above, there are techniques and best practices one can use to avoid duplicated code in Rules DSL that don’t involve lambdas. Based on experience, you can probably reduce your lines of code by 60-80% using those techniques.