vine.funtools

vine.funtools.maybe_promise(p)
vine.funtools.ensure_promise(p)
vine.funtools.ppartial(p, *args, **kwargs)
vine.funtools.preplace(p, *args, **kwargs)
vine.funtools.ready_promise(callback=None, *args)
vine.funtools.starpromise(fun, *args, **kwargs)
vine.funtools.transform(filter_, callback, *filter_args, **filter_kwargs)

Filter final argument to a promise.

E.g. to coerce callback argument to int:

transform(int, callback)

or a more complex example extracting something from a dict and coercing the value to float:

def filter_key_value(key, filter_, mapping):
    return filter_(mapping[key])

def get_page_expires(self, url, callback=None):
    return self.request(
        'GET', url,
        callback=transform(get_key, callback, 'PageExpireValue', int),
    )
vine.funtools.wrap(p)

Wrap promise so that if the promise is called with a promise as argument, we attach ourselves to that promise instead.