A method that generates a function which will wrap the function `f` and call the invariant with (before, arg1, arg2, ...)
170731
function _constructInvariant(f, invariant) {
    return function _wrapped() {
        var before = JSON.parse(JSON.stringify(this));
        var ret = f.apply(this, arguments);
        var arr = [before];
        invariant.apply(this, arr.concat.apply(arr, arguments));
        return ret;
    };
}
860725
def _make_wrapper(f):
    """"""
    @wraps(f)
    def wrapper(*args, **kwargs):
        return f(*args, **kwargs)
    wrapper._pecan = f._pecan.copy()
    return wrapper
280985
function wrap(fn, wrapper) {
        if (!wrapper)
            wrapper = function(f){ f.apply(this, slice.call(arguments, 1)) }

        return partial(wrapper, fn)
    }
294563
def wrap_with_scope(func, scope_name=None):
    ''''''
    if scope_name is None:
        scope_name = get_current_scope().name
    return lambda *args, scope=scope_name, **kwargs: \
           _call_with_scope(func, scope, args, kwargs)
1263146
function createWrapper(fn, ctx) {
  return function() {
    return new Promise(function(resolve, reject) {
      var start = Date.now();

      var cb = function(err) {
        if (err) return reject(err);
        resolve(Date.now() - start);
      };

      // Wrap generator functions
      if (fn && fn.constructor.name === 'GeneratorFunction') {
        fn = Promise.coroutine(fn);
      }

      var res = fn.call(ctx || this, cb);

      // Synchronous spec, or using promises rather than callbacks
      if (!fn.length || (res && res.then)) {
        Promise.resolve(res).then(function() {
          resolve(Date.now() - start);
        }, reject);
      }
    });
  };
}
1102894
function nextFunc(f1, f2) {
    if (f1 && !f2) return f1;
    if (f2 && !f1) return f2;
    return function nextFunc$wrapper(...args) {
        if (f1.apply(this, args) !== false) {
            return f2.apply(this, args);
        }
    };
}
215319
function _constructPre(f, pre) {
    return function _wrapped() {
        pre.apply(this, arguments);
        return f.apply(this, arguments);
    };
}
443243
function generateForever(f, init = null) {
  return function *_generateForever() {
    var args = yield init;
    while (true) args = yield f.apply(0, args);
  };
}
903631
def _gdecorator(generate_func):
        
        def dostuff(self):
            for func in self._pregenerate_functions:
                self.current_params = func(self.current_params)
            res = generate_func(self) # pylint:disable=not-callable
            return self._postgenerate(res)
        return dostuff
525414
def _wrap_callback_args(f, docstring=None):  # pragma: no cover
    
    def wrapped(checked, *args):
        if args:
            return f(*args)
        if isinstance(f, partial):
            argspec = inspect.getargspec(f.func)
        else:
            argspec = inspect.getargspec(f)
        f_args = argspec.args
        if 'self' in f_args:
            f_args.remove('self')
        # Remove arguments with defaults from the list.
        if len(argspec.defaults or ()):
            f_args = f_args[:-len(argspec.defaults)]
        # Remove arguments supplied in a partial.
        if isinstance(f, partial):
            f_args = f_args[len(f.args):]
            f_args = [arg for arg in f_args if arg not in f.keywords]
        # If there are no remaining args, we can just run the fu nction.
        if not f_args:
            return f()
        # There are args, need to display the dialog.
        # Extract Example: `...` in the docstring to put a predefined text
        # in the input dialog.
        r = re.search('Example: `([^`]+)`', docstring)
        docstring_ = docstring[:r.start()].strip() if r else docstring
        text = r.group(1) if r else None
        s, ok = _input_dialog(getattr(f, '__name__', 'action'),
                              docstring_, text)
        if not ok or not s:
            return
        # Parse user-supplied arguments and call the function.
        args = _parse_snippet(s)
        return f(*args)
    return wrapped
278155
def wrap(func):
    
    @functools.wraps(func, assigned=('restype', 'argtypes'))
    def wrapped(*args):
        if len(args) != len(func.argtypes):
            logger.warn("{} {} not of same length",
                        args, func.argtypes)

        typed_args = []
        for (arg, argtype) in zip(args, func.argtypes):
            if argtype == c_char_p:
                # create a string buffer for strings
                typed_arg = create_string_buffer(arg)
            else:
                # for other types, use the type to do the conversion
                if hasattr(argtype, 'contents'):
                    # type is a pointer
                    typed_arg = argtype(argtype._type_(arg))
                else:
                    typed_arg = argtype(arg)
            typed_args.append(typed_arg)
        result = func(*typed_args)
        if hasattr(result, 'contents'):
            return result.contents
        else:
            return result
    return wrapped
1287596
def wrap_in_fn_call(fn_name, args, prefix=None):
    
    assert len(args) > 0
    if len(args) == 2:
        expr1, expr2 = args
        newargs = [expr1, Comma(), expr2]
    else:
        newargs = args
    return Call(Name(fn_name), newargs, prefix=prefix)
476705
public static <T, R> Function<T, R> wrap(final Function<T, R> function)
	{
		final Tracing tracing = Tracing.get();

		final String traceId = tracing.newOperationId();
		return wrap(traceId, tracing.isVerbose(), function);
	}
245555
def decorator(caller, _func=None):
    """"""
    if _func is not None:  # return a decorated function
        # this is obsolete behavior; you should use decorate instead
        return decorate(_func, caller)
    # else return a decorator function
    if inspect.isclass(caller):
        name = caller.__name__.lower()
        callerfunc = get_init(caller)
        doc = 'decorator(%s) converts functions/generators into ' \
            'factories of %s objects' % (caller.__name__, caller.__name__)
        fun = getfullargspec(callerfunc).args[1]  # second arg
    elif inspect.isfunction(caller):
        if caller.__name__ == '<lambda>':
            name = '_lambda_'
        else:
            name = caller.__name__
        callerfunc = caller
        doc = caller.__doc__
        fun = getfullargspec(callerfunc).args[0]  # first arg
    else:  # assume caller is an object with a __call__ method
        name = caller.__class__.__name__.lower()
        callerfunc = caller.__call__.__func__
        doc = caller.__call__.__doc__
        fun = getfullargspec(callerfunc).args[1]  # second arg
    evaldict = callerfunc.__globals__.copy()
    evaldict['_call_'] = caller
    evaldict['_decorate_'] = decorate
    return FunctionMaker.create(
        '%s(%s)' % (name, fun),
        'return _decorate_(%s, _call_)' % fun,
        evaldict, call=caller, doc=doc, module=caller.__module__,
        __wrapped__=caller)
905652
def get_function_call_repr(fn, args, kwargs):
    """"""

    result = get_full_name(fn) + "("
    first = True
    for v in args:
        if first:
            first = False
        else:
            result += ","
        result += repr(v)
    for k, v in kwargs.items():
        if first:
            first = False
        else:
            result += ","
        result += str(k) + "=" + repr(v)
    result += ")"
    return result
77630
function wrapFn(fn) {

  var argCount = fn.length;

  if (argCount < 2) {
    // promise style worker
    return async function(context) {
      return await fn(context);
    };
  }

  if (argCount === 2) {
    // callback style worker
    return function(context) {

      return new Promise(function(resolve, reject) {
        try {
          fn(context, function(err, data) {
            if (err) {
              reject(err);
            } else {
              resolve(data);
            }
          });
        } catch (err) {
          reject(err);
        }
      });

    };
  }

  throw new Error('expected Promise or callback style fn');
}
682650
def _walk_decorator_stack(func: CallableT) -> Iterable['CallableT']:
    
    while hasattr(func, "__wrapped__"):
        yield func

        func = getattr(func, "__wrapped__")

    yield func