Flavored Booleans¶
For when different flavors of the truth matter.
- final class pythonic_fp.booleans.flavored.FBool¶
Bases:
SBoolFavored Booleans
When different flavors of the truth matter. Each
FBoolis anSBoolsubtype corresponding to a hashable flavor.Warning
Combining FBool instances of different flavors with bitwise operators will result in a runtime ValueError exception.
- static __new__(cls, witness: object, flavor: Hashable) Self¶
new
Traditional singleton pattern but with a ClassVar dict to store the for truthy or falsy singleton for each hashable flavor.
- param witness:
Determines truthiness of the FBool instance returned.
- param flavor:
The flavor of FBool to created.
- returns:
The truthy or falsy FBool instance of a particular flavor.
- __init__(witness: object, flavor: Hashable) None¶
initialize
Let the flavored boolean know its flavor.
- param witness:
Determines truthiness of the FBool instance returned.
- param flavor:
The flavor of FBool to created.
- type flavor:
H: Hashable
- returns:
The truthy or falsy FBool instance of a particular flavor.
- raises ValueError:
If different flavors compared with bitwise operators.
- __and__(other: int) int¶
bitwise and operator
Overloading
&to perform Boolean “and” ifotheris another FBool of the same flavor.- param other:
Any object derived from int.
- returns:
Boolean “and” if other is an FBool of the same flavor, otherwise returns bitwise “and”.
- raises:
ValueError if other is an FBool of a different flavor.
- __or__(other: int) int¶
bitwise or operator
Overloading
|to perform Boolean “or” ifotheris another FBool of the same flavor.- param other:
Any object derived from int.
- returns:
Boolean “or” if other is an FBool of the same flavor, otherwise returns bitwise “or”.
- raises:
ValueError if other is an FBool of a different flavor.
- __xor__(other: int) int¶
bitwise xor operator
Overloading
^to perform Boolean “xor” ifotheris another FBool of the same flavor.- param other:
Any object derived from int.
- returns:
Boolean “xor” if other is an FBool of the same flavor, otherwise returns bitwise “or”.
- raises:
ValueError if other is an FBool of a different flavor.
- __repr__() str¶
repr string
Create strings of the form
FBool(True, repr_flavor)FBool(False, repr_flavor)
Where
repr_flavor = repr(self.flavor())- returns:
A String to reproduce the flavored boolean.
- __str__() str¶
user string
Create strings of the form
FBool(True, str_flavor)FBool(False, str_flavor)
Where
str_flavor = str(self.flavor())- returns:
A String meaningful to an end user.
- flavor() Hashable¶
flavor
Get the flavor of the
FBool, a hashable value.- returns:
The flavor of the FBool.