aspis.common.apply_spec

aspis.common.apply_spec(spec, *args, **kwargs)[source]

Given a spec object recursively mapping properties to functions, creates a function producing an object of the same structure, by mapping each property to the result of calling its associated function with the supplied arguments.

Parameters:
  • spec (dict) – A dictionary mapping properties to functions.

  • *args (Any) – The arguments to be passed to the functions.

  • **kwargs (Any) – The keyword arguments to be passed to the functions.

Returns:

An object with the same structure as spec where each property is the result

of calling the associated function with the arguments.

Return type:

Mapping

Example

>>> from aspis.common import add, multiply
>>> get_metrics = apply_spec({"sum": add, "product": multiply})
>>> get_metrics(2, 3)
{'sum': 5, 'product': 6}