module subtypable¶
Subtypable Boolean.
Like Python’s built in bool, class SBool is a subclass of int.
Unlike bool, this version can be further subclassed.
This type and its subtypes can also do (non-shortcut) Boolean logic using Python bitwise operators.
Boolean operation |
symbol |
dunder |
|---|---|---|
not |
|
__invert__ |
and |
|
__and__ |
or |
|
__or__ |
xor |
|
__xor__ |
Note
These operators are contravariant, that is they will return the instance of the latest common ancestor of their arguments. More specifically, the instance returned will have the type of the least upper bound in the inheritance graph of the classes of the two arguments.
While compatible with Python short-cut logic. Unfortunately, the
not operator always returns a bool. Use the bitwise ~
operator to return an opposite SBool class or subclass.
Warning
The “bitwise” operators can raise TypeError exceptions
when applied against an SBool and objects not descended
from int.
- class pythonic_fp.booleans.subtypable.SBool¶
- class pythonic_fp.booleans.subtypable.SBool(witness: object)
- Parameters:
witness – Determines truthiness of the
SBool.- Returns:
The truthy or falsy SBool class instance.
- static __new__(cls) SBool¶
- static __new__(cls, witness: object) SBool
- Parameters:
witness – Determines truthiness of the
SBool.- Returns:
The truthy or falsy SBool class instance.
- __init__(witness: object = False, flavor: Hashable = NoValue()) None¶
- __repr__() str¶
Return repr(self).
- __and__(other: int) int¶
Return self&value.
- __or__(other: int) int¶
Return self|value.
- __xor__(other: int) int¶
Return self^value.