def __init__(self, func, items, cache=True):
"""Applies the given function on the given items at the moment of data request.
On the moment one of the keys of this dict class is requested we apply the given function on the given items
and return the result of that function. The advantage of this class is that it defers an expensive operation
until it is needed.
Items added to this dictionary after creation are assumed to be final, that is, we won't run the
function on them.
Args:
func (Function): the callback function to apply on the given items at request, with signature:
.. code-block:: python
def callback(key, value)
items (collections.MutableMapping): the items on which we operate
cache (boolean): if we want to cache computed results
"""
self._func = func
self._items = copy.copy(items)
self._applied_on_key = {}
self._cache = cache
评论列表
文章目录