Skip to content

Latest commit

 

History

History
62 lines (45 loc) · 2.03 KB

checkers.rst

File metadata and controls

62 lines (45 loc) · 2.03 KB

Checkers

Abstract Base Checker

.. autoclass:: glompo.convergence.basechecker.BaseChecker
   :members:
   :special-members: __str__
   :inherited-members: str_with_result

Combining Base Checkers

Instances of :class:`.BaseChecker` can be combined with & and | boolean operations. This allows individual checkers to be very simple, but be combined into more sophisticated conditions. Combining checkers in this way produces a new :class:`.BaseChecker` object which itself can be further combined. This allows conditions to be as deeply nested as one desires. For example:

>>> a = CheckerA()
>>> b = CheckerB()
>>> c = CheckerC()
>>> d = CheckerD()
>>> combi = a & b | c & d

The order of evaluation is & before |, thus the above would be equivalent to:

>>> combi = ((a & b) | (c & d))

Important

A combined :class:`.BaseChecker` is evaluated lazily. This means:

  1. a & b will not evaluate b if a is :obj:`False`
  2. a | b will not evaluate b if a is :obj:`True`

Lazy evaluation ensures a faster return, and explains the presence of :obj:`None` when a hunt evaluation statement is printed. For example:

>>> combi(...)
True
>>> from glompo.common.helpers import nested_string_formatting
>>> nested_string_formatting(combi.str_with_result())
'[
  CheckerA() = True &
  CheckerB() = True
 ] |
 [
  CheckerC() = None &
  CheckerD() = None
 ]'

Make sure to structure your nesting in the correct order. For example, if you want to make sure a certain checker is always evaluated, place it first. If a checker is slow to evaluate, place it last.

All of the above holds true for :ref:`Hunters` too as they share a common hidden base.

Included Checkers

For convenience, GloMPO comes bundled with several simple checkers already included.

.. automodule:: glompo.convergence
   :members:
   :show-inheritance:
   :exclude-members: BaseChecker