# vine.funtools

Functional utilities.

vine.funtools.ensure_promise(p)

  Ensure p is a promise.

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

vine.funtools.maybe_promise(p)

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

vine.funtools.ppartial(p, *args, **kwargs)

  Create/modify promise with partial arguments.

vine.funtools.preplace(p, *args, **kwargs)

  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)

  Create promise that is already fulfilled.

vine.funtools.starpromise(fun, *args, **kwargs)

  Create promise, using star arguments.

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.

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