vine.funtools

Functional utilities.

vine.funtools.maybe_promise(p)[source]

Return None if p is unefined, otherwise make sure it’s a promise.

vine.funtools.ensure_promise(p)[source]

Ensure p is a promise.

If p is not a promise, a new promise is created with p’ as callback.

vine.funtools.ppartial(p, *args, **kwargs)[source]

Create/modify promise with partial arguments.

vine.funtools.preplace(p, *args, **kwargs)[source]

Replace promise arguments.

This will force the promise to disregard any arguments the promise is fulfilled with, and to be called with the provided arguments instead.

vine.funtools.ready_promise(callback=None, *args)[source]

Create promise that is already fulfilled.

vine.funtools.starpromise(fun, *args, **kwargs)[source]

Create promise, using star arguments.

vine.funtools.transform(filter_, callback, *filter_args, **filter_kwargs)[source]

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)[source]

Wrap promise.

This wraps the promise such that if the promise is called with a promise as argument, we attach ourselves to that promise instead.