truthy_falsy

class pythonic_fp.booleans.truthy_falsy.TF_Bool

Bases: SBool

Truthy-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 NEVER but not ALWAYS is False because ALWAYS is truthy.

Similarly, (ALWAYS and False) is False while (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.

__invert__() TF_Bool

~self

__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_Bool

Truthy 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_Bool

Falsy 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.

pythonic_fp.booleans.truthy_falsy.ALWAYS: Final[TF_Bool] = TF_Bool(True)

ALWAYS

var ALWAYS:

The truthy singleton TF_Bool subtyped instance.

pythonic_fp.booleans.truthy_falsy.NEVER: Final[TF_Bool] = TF_Bool(False)

Never

var NEVER:

The falsy singleton TF_Bool subtyped instance.