Module wonderful.util.func

Various function utilities (eg cache).

Functions

cached(func[, entries=math.huge]) Decorate a function to cache results of execution.
cached1arg(func[, entries=math.huge], pos) Decorate a function to cache results of execution.


Functions

cached(func[, entries=math.huge])
Decorate a function to cache results of execution. When such a function is called, checks if the cache contains an entry for such arguments. If it does, returns the entry. Otherwise, the original function is called, and the result is stored in cache.

The original function must return the same result if called with the same arguments.

The number of entries stored in cache can be limited.

Parameters:

  • func function a function to decorate
  • entries int a cache size limit (default math.huge)

Returns:

    function the decorated function
cached1arg(func[, entries=math.huge], pos)
Decorate a function to cache results of execution. Only a single argument is stored. Works considerably faster than wonderful.util.func.cached in such cases.

Parameters:

  • func function a function to decorate
  • entries number a cache size limit (default math.huge)
  • pos int an index of argument to cache

Returns:

    function the decorated function

See also:

generated by LDoc 1.4.6 Last updated 2018-10-06 09:21:37