truthy_falsy¶
- class pythonic_fp.booleans.truthy_falsy.TF_Bool¶
Bases:
SBoolTruthy-Falsy Booleans
A Boolean implementation whose distinct truthy and falsy values are distinct singleton subclasses, not just distinct singleton values.
A subtype of SBool.
Tip
Logically combine these using Python’s bitwise operators.
Warning
Although these datastructures are completely compatible with Python shortcut evaluation, care needs to be taken when using them with the “and”, “or”, and “not” builtins.
For example,
~ALWAYS is NEVERbutnot ALWAYS is FalsebecauseALWAYSis truthy.Similarly,
(ALWAYS and False) is Falsewhile(ALWAYS or False) is ALWAYS.- static __new__(cls, witness: object, flavor: Hashable = NoValue()) Self¶
new
- param witness:
Determines which subtype, T_Bool or F_Bool to return.
- param flavor:
Ignored parameter, only two flavors, one truthy and one falsy.
- returns:
The singleton truthy or singleton falsy instances.
- __repr__() str¶
repr string
if truthy return ‘TF_Bool(True)’
if falsy return ‘TF_Bool(False)’
- returns:
A string to reproduce the TF_Bool.
- __str__() str¶
user string
if truthy return ‘ALWAYS’
if falsy return ‘NEVER’
- returns:
A string meaningful to an end user.
- class pythonic_fp.booleans.truthy_falsy.T_Bool¶
Bases:
TF_BoolTruthy TF_Bool subclass
Type of the truthy singleton TS_Bool instance. A distinct type from F_Bool.
- static __new__(cls, witness: object = NoValue(), flavor: Hashable | NoValue = NoValue()) Self¶
new
- param witness:
Ignored parameter, a T_Bool is always truthy.
- param flavor:
Ignored parameter, only one truthy “flavor”.
- returns:
The truthy T_Bool singleton instance.
- __and__(other: int) int¶
Return self&value.
- __or__(other: int) int¶
Return self|value.
- __xor__(other: int) int¶
Return self^value.
- class pythonic_fp.booleans.truthy_falsy.F_Bool¶
Bases:
TF_BoolFalsy TF_Bool subclass
Type of the falsy singleton TS_Bool instance. A distinct type from T_Bool.
- static __new__(cls, witness: object = NoValue(), flavor: Hashable | NoValue = NoValue()) Self¶
new
- param witness:
Parameter ignored, an F_Bool is always falsy.
- param flavor:
Parameter ignored, only one falsy “flavor”.
- returns:
The falsy F_Bool singleton instance.
- __and__(other: int) int¶
Return self&value.
- __or__(other: int) int¶
Return self|value.
- __xor__(other: int) int¶
Return self^value.