def once(f):
    """Decorator. Defer to f once and only once, caching the result forever.

    Users with a functional background may recognize the concept of a `thunk`.

    """

    unset = val = object()

    def _helper(*args, **kwargs):
        nonlocal val
        if val is unset:
            val = f(*args, **kwargs)
        return val

    return _helper