python_project_template_AS.calculator#

Calculator utilities for applying and composing operations.

The Calculator provides a thin layer over OperationRegistry. It supports applying named operations, composing unary operations into a callable, and a small ‘chain’ helper for mixed sequences of unary/binary operations used by the examples and tests.

Keep the behaviour minimal: methods raise OperationError for operation-related failures.

Classes

Calculator([registry])

Calculator using an OperationRegistry.

class python_project_template_AS.calculator.Calculator(registry=None)[source]#

Bases: object

Calculator using an OperationRegistry.

Parameters:

registry (OperationRegistry | None)

apply(op_name, *args)[source]#

Apply a named operation with arguments.

Return type:

Any

Parameters:
  • op_name (str)

  • args (Any)

chain(sequence, initial)[source]#

Apply a sequence of operations and values starting from initial.

Return type:

Any

Parameters:
  • sequence (Iterable[str | int])

  • initial (Any)

compose(ops, *, left_to_right=True)[source]#

Compose unary operations into a single callable.

Return type:

Callable[[Any], Any]

Parameters:
  • ops (Iterable[str])

  • left_to_right (bool)

register(op, *, replace=False)[source]#

Register an operation, optionally replacing existing.

Return type:

None

Parameters: