collection.toggleable_bool

Add set of conditional booleans that can be used to explore many combinations.

ToggleableBoolean are meant to be grouped and their value can be toggled to explore all possible combinations. This can be useful when there is an expression depending on external values that you want to evaluate without knowing in advance the external environment.

Module Contents

Classes

ToggleableBooleanGroup

Contain group of toggleable boolean.

ToggleableBoolean

Contain a boolean value that can be toggle in group.

class collection.toggleable_bool.ToggleableBooleanGroup

Contain group of toggleable boolean.

Add a new boolean by calling .add(<name>, <bool value>). Then generate all possible combinations by running .shuffle():

group = ToggleableBooleanGroup()
group.add('first', True)
group.add('second', False)

for series in group.shuffle():
    print([str(b) for b in series])

Will display:

['first: True', 'second: True']
['first: False', 'second: True']
['first: False', 'second: False']
__getitem__(key: int) ToggleableBoolean

Get a toggleable boolean by index.

Parameters:

key – index of the toggleable boolean

__len__() int

Return the number of elements in the series.

shuffle() collections.abc.Iterator[list[ToggleableBoolean]]

Generate all other possible set of values for all conditional booleans.

Returns:

yield a new list of ToggleableBoolean with a different set of value. Calling this function until StopIteration is raised will generate all possible values except the initial set of value.

add(name: str, value: bool) ToggleableBoolean

Create a new boolean value and add it to this group.

Parameters:
  • name – boolean name for debug info

  • value – boolean value

class collection.toggleable_bool.ToggleableBoolean(name: str, value: bool)

Contain a boolean value that can be toggle in group.

See ToggleableBooleanGroup.

__bool__() bool

Return boolean value of toggleable boolean.

__str__() str

Return string representation of toggleable boolean.