zeroSteiner / rule-engine

A lightweight, optionally typed expression language with a custom grammar for matching arbitrary Python objects.
https://zerosteiner.github.io/rule-engine/
BSD 3-Clause "New" or "Revised" License
455 stars 54 forks source link

Better support for arrays reduction functions #49

Closed eblis closed 1 year ago

eblis commented 1 year ago

I'm in the bandwagon requesting the ability to call functions in the engine, but I think my use case is not as involved as some of the other users.

I'm trying to check if an any or all values in an array match a certain rule. How hard would it be to add just these 2 methods, which operate on arrays alone and their result is a single value.

One example:

items = [1, 2, 3, 4, 5, 6, 7, 8, 9]
rule = rule_engine.Rule("any(items > 3)")

You could probably achieve the same effect by doing something like this, which is valid

rule = rule_engine.Rule("[x for x in items if x > 3]"

and then checking if there are any values left, but that's harder to read imo and harder to chain multiple checks.

zeroSteiner commented 1 year ago

Well as you said you can already use list comprehension to achieve the same effect.

Closing as a duplicate of #32.