creates an enhancer function composed of middleware

    Args:
        *middlewares: list of middleware functions to apply

    Returns:
        an enhancer for subsequent calls to create_store()
177651
def apply_middleware(*middlewares):
    
    def inner(create_store_):
        def create_wrapper(reducer, enhancer=None):
            store = create_store_(reducer, enhancer)
            dispatch = store['dispatch']
            middleware_api = {
                'get_state': store['get_state'],
                'dispatch': lambda action: dispatch(action),
            }
            chain = [mw(middleware_api) for mw in middlewares]
            dispatch = compose(*chain)(store['dispatch'])

            return extend(store, {'dispatch': dispatch})
        return create_wrapper
    return inner
419286
public static function addStaticMiddlewares(...$middlewares): array
    {
        $stack = static::getStaticMiddlewareStack(true);
        foreach ($middlewares as $middleware) {
            $stack->append($middleware);
        }
        return $middlewares;
    }
400941
function createStore(descriptor) {
    var store = new pastore_1.XStore(descriptor.initState);
    store.name = descriptor.name;
    if (descriptor.actions)
        store.actions = descriptor.actions;
    if (descriptor.middlewares)
        store.actionMiddlewares = descriptor.middlewares;
    return store;
}
1111630
def combine_middlewares(middlewares, web3, provider_request_fn):
    
    return functools.reduce(
        lambda request_fn, middleware: middleware(request_fn, web3),
        reversed(middlewares),
        provider_request_fn,
    )
609838
function (routerMiddelware, req, res, next) {
		var middlewareFilename = routerMiddelware.split('.')[0];
		var middlewareFunction = routerMiddelware.split('.')[1];

		if (!req.pipa) req.pipa = {};

		this.middlewares[middlewareFilename][middlewareFunction](req, res, function (data) {
			_.extend(req.pipa, data); next();
		});
	}
302302
def construct_fixture_middleware(fixtures):
    
    def fixture_middleware(make_request, web3):
        def middleware(method, params):
            if method in fixtures:
                result = fixtures[method]
                return {'result': result}
            else:
                return make_request(method, params)
        return middleware
    return fixture_middleware
1159334
function compose(middleware){
	return function *(next){
		if (!next) next = noop();

		var i = middleware.length;

		while (i--) {
			next = middleware[i].call(this, next);
		}

		yield *next;
	}
}
629695
function createEntries(plugins) {
    return _.chain(plugins)
        .map(function (plugin) {
            let entry = _.get(plugin, 'raw.plugin.entry')

            if (!Array.isArray(entry)) {
                entry = [entry]
            }

            return entry.reduce(function (result, value) {
                if (value) {
                    result.push(createEntry(path.join(plugin.path, value)))
                }
                return result
            }, [])
        })
        .flatten()
        .compact()
        .value()
}
345357
function compose () {
  // the function required by the server
  function middlewareF (req, res, end) {
    var index = 0

    // inject stats middleware
    if (middlewareF.options && middlewareF.options.stats) {
      middlewareF.stack = middlewareF.stack.map(function (mw) {
        var fn
        if (typeof mw === 'object') {
          var key = Object.keys(mw)[0]
          if (!mw[key].stats) {
            fn = {}
            fn[key] = middlewareF.options.stats(mw[key])
          }
        } else {
          if (!mw.stats) {
            fn = middlewareF.options.stats(mw)
          }
        }
        return fn
      })
    }

    // looping over all middleware functions defined by stack
    ;(function next (err) {
      var arity
      var middleware = middlewareF.stack[index++] // obtain the current middleware from the stack

      if (!middleware) {
        // we are at the end of the stack
        end && end(err)
        return
      } else {
        // extract middleware from object
        if (typeof (middleware) === 'object') {
          var name = Object.keys(middleware)[0]
          if (typeof (middleware[name]) === 'function') {
            middleware = middleware[name]
          } else {
            middleware = function (req, res, next) {
              next(new Error('missing middleware'))
            }
          }
        }

        try {
          arity = middleware.length // number of arguments function middleware requires
          // handle errors
          if (err) {
            // If the middleware function contains 4 arguments than this will act as an "error trap"
            if (arity === 4) {
              middleware(err, req, res, function (err) {
                nextTick(next, err)
              })
            } else {
              // otherwise check the next middleware
              next(err)
            }
          } else if (arity < 4) {
            // process non "error trap" stack
            middleware(req, res, function (err) {
              nextTick(next, err)
            })
          } else {
            // loop over "error traps" if no error `err` is set.
            next()
          }
        } catch (e) {
          next(e)
        }
      }
    })()
  }

  middlewareF.stack = []
  middlewareF.options = compose.options || {}

  ;[].slice.call(arguments).forEach(function (a) {
    middlewareF.stack = middlewareF.stack.concat(compose.decompose(a))
  })

  // extends
  ;[ 'before', 'after', 'replace', 'remove', 'push', 'unshift', 'clone' ].forEach(function (p) {
    middlewareF[p] = compose[p]
  })

  // inject stats middleware
  if (compose.options.stats) {
    middlewareF.options = {}
    middlewareF.options.stats = compose.options.stats
  }

  return middlewareF
}
973241
def install_middleware(self):
        
        from django.conf import settings

        # If MIDDLEWARE is set, update that, with handling of tuple vs array forms
        if getattr(settings, "MIDDLEWARE", None) is not None:
            if isinstance(settings.MIDDLEWARE, tuple):
                settings.MIDDLEWARE = (
                    ("scout_apm.django.middleware.MiddlewareTimingMiddleware",)
                    + settings.MIDDLEWARE
                    + ("scout_apm.django.middleware.ViewTimingMiddleware",)
                )
            else:
                settings.MIDDLEWARE.insert(
                    0, "scout_apm.django.middleware.MiddlewareTimingMiddleware"
                )
                settings.MIDDLEWARE.append(
                    "scout_apm.django.middleware.ViewTimingMiddleware"
                )

        # Otherwise, we're doing old style middleware, do the same thing with
        # the same handling of tuple vs array forms
        else:
            if isinstance(settings.MIDDLEWARE_CLASSES, tuple):
                settings.MIDDLEWARE_CLASSES = (
                    ("scout_apm.django.middleware.OldStyleMiddlewareTimingMiddleware",)
                    + settings.MIDDLEWARE_CLASSES
                    + ("scout_apm.django.middleware.OldStyleViewMiddleware",)
                )
            else:
                settings.MIDDLEWARE_CLASSES.insert(
                    0, "scout_apm.django.middleware.OldStyleMiddlewareTimingMiddleware"
                )
                settings.MIDDLEWARE_CLASSES.append(
                    "scout_apm.django.middleware.OldStyleViewMiddleware"
                )
1093056
function compose(middleware){
	return function *(next){
		var i = middleware.length;
		next = next || function *(){};
		var mw;

		while (i--) {
			mw = middleware[i];
			next = mw.call(this, next);
		}

		yield *next;
	}
}
466319
function makeRespondMiddleware(opts) {
  opts = Object.assign({}, opts)

  // Make the respond function.
  const respond = makeRespond(opts)

  /**
   * Installs the functions in the context.
   *
   * @param  {KoaContext} ctx
   */
  function patch(ctx) {
    const statusMethods = Object.assign({}, opts.statusMethods, statusCodeMap)
    ctx.send = respond.bind(ctx, ctx)

    // Bind status methods.
    for (const method in statusMethods) {
      const code = statusMethods[method]
      ctx[method] = respond.bind(ctx, ctx, code)
    }

    // Bind other methods
    const methods = Object.assign({}, opts.methods)
    for (const method in methods) {
      const fn = methods[method]
      ctx[method] = fn.bind(ctx, ctx)
    }

    return ctx
  }

  /**
   * The respond middleware adds the methods to the context.
   *
   * @param  {KoaContext} ctx
   */
  function respondMiddleware(ctx, next) {
    patch(ctx)
    return next()
  }

  // Tack on the patch method to allow Koa 1 users
  // to install it, too.
  respondMiddleware.patch = patch
  return respondMiddleware
}
1055579
async function createApp(middlewareConfig) {
  const app = new Koa()

  const middleware = await setupMiddleware(middlewareConfig, app)

  if (app.env == 'production') {
    app.proxy = true
  }

  return {
    app,
    middleware,
  }
}
143159
private function composeMiddleware(array $middlewares)
  {
    $curryedMiddlewares = array_map(function($middleware) {
      return function (\Closure $next) use ($middleware) {
        return function (MessageInterface $requestOrResponse) use ($middleware, $next) {
          return call_user_func($middleware, $next, $requestOrResponse);
        };
      };
    }, array_reverse($middlewares));

    return array_reduce($curryedMiddlewares, function($state, $middleware){
      return function(MessageInterface $requestOrResponse) use ($state, $middleware) {
        return $middleware($state)($requestOrResponse);
      };
    }, function($requestOrResponse) {
      return $requestOrResponse;
    });
  }
1149966
def prepare_middleware(&context_definition)
      last_middleware = AllImportantMiddleware.new(&context_definition)
      Context.middlewares.inject(last_middleware) do |previous_middleware, middleware|
        middleware.new(previous_middleware)
      end.call(self)
    end
279131
function middleware(definition, resolver, options) {
  const customExecution = options.factoryExecution !== false;
  const resolve = function(source, args, context, info) {
    // ensure that context is an object and extend it
    const ctx = _.isObjectLike(context) ? context : {};
    Object.assign(ctx, definition.context);
    info.definition = definition;

    return customExecution
      ? factoryExecute(source, args, ctx, info)
      : graphqlExecute(source, args, ctx, info);
  };

  // add the resolver as a property on the resolve middleware
  // function so that when deconstructing the schema the original
  // resolver is preserved. Also add a flag that identifies this
  // resolver as factory middleware
  resolve.__resolver = resolver;
  resolve.__factoryMiddleware = true;
  return resolve;
}
945773
function use(events, middleware)
{
  // if no middleware supplied assume it's single argument call
  if (!middleware)
  {
    middleware = events;
    events     = null;
  }

  // make it uniform
  events = normalizeEvents(events);

  // store middleware per event
  events.forEach(function(e)
  {
    // bind middleware to the current context
    (this._stack[e] = this._stack[e] || []).push(middleware.bind(this));

    // make mark in history
    this.logger.debug({message: 'Added middleware to the stack', event: e, middleware: middleware});
  }.bind(this));
}