Closed kuldeeprishi closed 3 years ago
I like this idea but I'd like to see it either implemented as:
set
datatype with support for bitwise operations like my_roles & their_roles
r for r in my_roles if r in their_roles
Neither of those would be particularly easy to implement so it might be a little while before I get around to this.
Hello, I am also interested in the intersect feature between arrays. My need would be to know if 2 lists have any element in common. Thank you!
+1 for set
support
I've started the work for a SET data type which would support the bitwise operators and, or and xor (&
, |
, and ^
respectively). Usage of the bitwise and operator will have the desired effect of checking for the intersection of two SETs just like it does in Python. There will be accompanying attributes for converting arrays and strings into sets. This will be in the 3.1 release (probably) in the next couple of weeks. A preview is available in the feat/v3.1 branch.
I'd still like to have array comprehension support, but that can come later. These two features don't seem like they need to be mutually exclusive and a SET data type will solve the problem at hand more directly.
Alright this is done in the v3.1.0 release which is now on PyPi. You can use the new SET data type along with the bitwise and operator &
. For example:
python -m rule_engine.debug_repl
rule > {"R1", "R2", "R3"} & {"R3", "R4"}
result:
{'R3'}
rule > 'Testing'.to_set & {'a', 'e', 'i', 'o', 'u'}
result:
{'e', 'i'}
rule >
Both the ARRAY and STRING data types have a to_set
attribute that will convert them as well.
Hi, is it possible to add support for intersect? eg: