override def run[T2 <: Seq[T], V]()

in src/main/scala/com/twitter/stitch/Arrow.scala [1252:1340]


    override def run[T2 <: Seq[T], V](
      ts: ArrayBuffer[Try[T2]],
      ls: ArrayBuffer[Locals],
      tail: Arrow[Seq[U], V]
    ): Stitch[ArrayBuffer[Try[V]]] = {
      var totalCount = 0
      var i = 0

      while (i < ts.length) {
        ts(i) match {
          case Return(seq) => totalCount += seq.length
          case _ =>
        }
        i += 1
      }

      if (totalCount == 0) {
        tail.run(ts.asInstanceOf[ArrayBuffer[Try[Seq[U]]]], ls)
      } else {
        val flattenedInput = new ArrayBuffer[Try[T]](totalCount)
        val flattenedLocals = new ArrayBuffer[Locals](totalCount)
        var i = 0

        while (i < ts.length) {
          ts(i) match {
            case Return(seq) =>
              val iter = seq.iterator
              while (iter.hasNext) {
                flattenedInput += Return(iter.next)
                flattenedLocals += ls(i)
              }

            case _ =>
          }

          i += 1
        }

        a.run(flattenedInput, flattenedLocals).flatMap { flattenedResults =>
          var i = 0
          var j = 0
          val splitResults = ts.asInstanceOf[ArrayBuffer[Try[Seq[U]]]]

          while (i < ts.length) {
            ts(i) match {
              case Return(seq) =>
                var iRes: Try[Seq[U]] = null
                var k = j
                val kEnd = j + seq.length

                // first pass, look for any Throws in the range `j` to `j + seq.length`
                while (k < kEnd && iRes == null) {
                  flattenedResults(k) match {
                    case t @ Throw(_) => iRes = t.asInstanceOf[Try[Seq[U]]]
                    case _ =>
                  }
                  k += 1
                }

                // if no Throws, then all results are Returns, and can be converted to a
                // a Return[Seq[U]]
                if (iRes == null) {
                  k = j
                  val buf = new ArrayBuffer[U](seq.length)

                  while (k < kEnd) {
                    flattenedResults(k) match {
                      case Return(x) => buf += x
                      case _ => scala.sys.error("stitch bug")
                    }
                    k += 1
                  }

                  iRes = Return(buf)
                }

                splitResults(i) = iRes
                j += seq.length

              case _ =>
            }

            i += 1
          }

          tail.run(splitResults, ls)
        }
      }
    }