maybeCallback := (fn: (Any, ...) => Continuable<T>) => (Any, ..., Callback<T>?) => Continuable<T>
16046
function maybeCallback(fn) {
    return function maybeContinuable() {
        var args = slice.call(arguments)
        var callback = args[args.length - 1]

        if (typeof callback === "function") {
            args.pop()
        }

        var continuable = fn.apply(null, args)

        if (typeof callback === "function") {
            continuable(callback)
        } else {
            return continuable
        }
    }
}
1276134
function (fn) {
    if (!fn || !_.isFunction(fn)) {
      var err = new Error('Please pass a valid function!');
      debug(err);
      throw err;
    }

    if (fn.length === 1) {
      fn = _.wrap(fn, function(func, cmd, callback) {
        func(cmd);
        callback(null);
      });
    }

    this.onCommandHandle = fn;

    return this;
  }
463913
function wrap(func) {
        if (typeof func !== 'function') {
            throw new Error('function argument is expected');
        }

        if (func.tasync_wraped === undefined) {
            func.tasync_wraped = function () {
                var args = arguments;
                var future = new Future();

                args[args.length++] = function (error, value) {
                    if (error) {
                        future.reject(error instanceof Error ? error : new Error(error));
                    } else {
                        future.resolve(value);
                    }
                };

                func.apply(this, args);

                if (future.state === STATE_LISTEN) {
                    return future;
                } else if (future.state === STATE_RESOLVED) {
                    return future.value;
                } else {
                    assert(future.state === STATE_REJECTED);
                    throw future.value;
                }
            };

            func.tasync_wraped.tasync_unwraped = func;
        }

        return func.tasync_wraped;
    }
636755
def _wrap(self, value, priority=0):
        

        if not callable(value):
            raise TypeError("Only callable values can be stored in CallbackContainer")

        elif self.is_bound_method(value):

            # We are dealing with a bound method. Method references aren't
            # persistent, so instead we store a reference to the function
            # and instance.

            value = (weakref.ref(value.__func__),
                     weakref.ref(value.__self__, self._auto_remove),
                     priority)

        else:

            value = (value, priority)

        return value
819840
def callable_validator(v: Any) -> AnyCallable:
    
    if callable(v):
        return v

    raise errors.CallableError(value=v)
395057
function hasCallback(node) {
    return isObject(node) &&
           isArray(node.arguments) &&
           node.arguments.some(isFunctionExpr);
}
1253934
def partial_regardless(self, fn, *a, **kw):
        """"""
        if self.has_annotations(fn):
            return self.partial(fn, *a, **kw)
        else:
            return functools.partial(fn, *a, **kw)
22706
function callOnce(fn) {
  var called = false

  return calledOnceShim

  //-----------------------------------
  function calledOnceShim() {
    if (called) return
    called = true

    fn.apply(this, arguments)
  }
}
808112
def map(self, fn: Callable[[Any], Any]) -> 'Cont':
        
        """
        return Cont(lambda c: self.run(compose(c, fn)))
545114
def maybe(func):
    """"""

    name = object_name(func)

    @wraps(func)
    def maybe_wrapped(*args, **kwargs):
        """@maybe wrapped version of ``func``."""
        fails = [
            (name, k, v)
            for k, v in chain(enumerate(args), kwargs.items())
            if isinstance(v, Fail)]

        if fails:
            return Fail(func, fails=fails)

        try:
            result = func(*args, **kwargs)

        except Exception as exc:
            return Fail(func, exception=exc)

        else:
            if isinstance(result, Fail):
                result.add_call(func)

            return result

    return maybe_wrapped
476607
function executeCallback(cb, arg) {
    var r = cb(arg)
    if(r !== undefined && !isLikeAFuture(r) )
        throw Error("Value returned from then or catch ("+r+") is *not* a Future. Callback: "+cb.toString())

    return r
}
832248
def bind(self, fn: Callable[[Any], 'Cont']) -> 'Cont':
        
        """
        return Cont(lambda c: self.run(lambda a: fn(a).run(c)))
44233
function (key, val, ttl, callback) {
            //ttl is optional
            if (_.isFunction(ttl)) {
                callback = ttl;
                ttl = undefined;
            }

            //callback is optional
            callback = callback || _.noop;
            client.set(key, val, ttl, callback);
        }
1013052
public static <T> Callable<T> callable(CheckedCallable<T> callable) {
        return Unchecked.callable(callable, Unchecked.RETHROW_ALL);
    }
112612
function callbackified() {
    var args = [];
    for (var i = 0; i < arguments.length; i++) {
      args.push(arguments[i]);
    }

    var maybeCb = args.pop();
    if (typeof maybeCb !== 'function') {
      throw new TypeError('The last argument must be of type Function');
    }
    var self = this;
    var cb = function() {
      return maybeCb.apply(self, arguments);
    };
    // In true node style we process the callback on `nextTick` with all the
    // implications (stack, `uncaughtException`, `async_hooks`)
    original.apply(this, args)
      .then(function(ret) { process.nextTick(cb.bind(null, null, ret)) },
            function(rej) { process.nextTick(callbackifyOnRejected.bind(null, rej, cb)) });
  }
335115
def sometimes(fn):
    

    def wrapped(*args, **kwargs):
        wrapped.x += 1
        if wrapped.x % 2 == 1:
            return fn(*args, **kwargs)

    wrapped.x = 0
    return wrapped
636816
def apply(self, fn, *a, **kw):
        """"""
        args, kwargs = self.prepare_callable(fn)
        args += a; kwargs.update(kw)
        return fn(*args, **kwargs)