flavored

final class pythonic_fp.booleans.flavored.FBool

Bases: SBool

Favored Booleans

When different flavors of the truth matter. Each FBool is an SBool subtype 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

Return self&value.

__or__(other: int) int

Return self|value.

__xor__(other: int) int

Return self^value.

__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 to meaningful to an end user.

flavor() Hashable

flavor

Get the flavor of the FBool, a hashable value.

returns:

The flavor.

pythonic_fp.booleans.flavored.truthy(flavor: Hashable) FBool

function truthy

Returns the truthy singleton FBool of a particular flavor.

param flavor:

Hashable value to determine which singleton flavor to return.

returns:

The truthy singleton of a particular flavor.

pythonic_fp.booleans.flavored.falsy(flavor: Hashable) FBool

Function falsy

Returns the falsy singleton FBool of a particular flavor.

param flavor:

Hashable value to determine which singleton flavor to return.

returns:

The falsy singleton of a particular flavor.