Decorate a function so that the result is a constant value.

    Functions wraped by this decorator will be run just one time.
    The computational result will be stored and reused for any other input.

    To store each result for each input, use :func:`memoized` instead.

def constant(func):
    """Decorate a function so that the result is a constant value.

    Functions wraped by this decorator will be run just one time.
    The computational result will be stored and reused for any other input.

    To store each result for each input, use :func:`memoized` instead.
    """
    @wraps(func)
    def _(*args, **kwargs):
        """The decorated function.
        """
        if not _.res:
            _.res = func(*args, **kwargs)
        return _.res
    _.res = None
    return _