docs: 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
  }