Python port of KeySet in TypeScript and KeySet in Ruby
KeySet with 4 classes to represent concepts of All, None, Some, and AllExceptSome, the last 2 with a set of keys, and all with intersection, difference, union, inversion, and inclusion calculations.
- for now, only KeySet of strings
- no ComposedKeySet yet (see KeySet in TypeScript)
Enum that represents the 4 types of KeySets:
ALL
represents the entirety of possible keys (𝕌
)NONE
represents an empty set (∅
)SOME
represents a concrete set (A ⊂ 𝕌
)ALL_EXCEPT_SOME
represents the complementary of a set, all the elements except the given ones (A' = {x ∈ 𝕌 | x ∉ A}
) _(see Complement in Wikipedia)*
Build your KeySets using the build functions
from key_set import build_all, build_none, build_some_or_none, build_all_except_some_or_all
build_all() # => returns a new instance of KeySetAll
build_none() # => returns a new instance of KeySetNone
build_some_or_none([]) # returns a new instance of KeySetNone
# returns a new instance of KeySetSome with keys {'a', 'b', 'c'} (in a unique set)
build_some_or_none({'a', 'c', 'b'})
build_some_or_none(['a', 'c', 'b', 'c'])
build_all_except_some_or_all([]) # returns a new instance of KeySetAll
# returns a new instance of KeySetAllExceptSome with keys {'a', 'b', 'c'} (in a unique set)
build_all_except_some_or_all({'a', 'c', 'b'})
build_all_except_some_or_all(['a', 'c', 'b', 'c'])
Methods exposed:
returns the KeySetType
enum
returns the set with the elements. It will be blank for All
and None
.
represents_all
: returns True if the KeySet is ALLrepresents_none
: returns True if the KeySet is NONErepresents_some
: returns True if the KeySet is SOMErepresents_all_except_some
: returns True if the KeySet is ALL_EXCEPT_SOME
Returns a new KeySet that represents the inverse Set of this one.
ALL
<->NONE
SOME
<->ALL_EXCEPT_SOME
Returns a new KeySet with the intersection (A ∩ B) of both Sets: a set that contains the elements included in both sets.
Returns a new KeySet with the union (A ∩ B) of both Sets: a set that contains the elements in any of the sets.
Returns a new KeySet with the difference (A - B) of the Sets: a set that contains the elements of A that are not in B.
Returns True if the set that this KeySet represents contains the given element.