override def simplify()

in src/main/scala/com/twitter/stitch/Stitch.scala [1962:2031]


    override def simplify(pending: Pending): Stitch[Seq[T]] = {
      if (forwarded ne null) return forwarded

      self match {
        case TransformSeq(ss, _, Arrow.Identity()) =>
          // when there is no continuation we can return an exception
          // as soon as we see it.
          // TODO(jdonham) we could also do this when there is a
          // continuation but it doesn't catch exceptions

          var satisfied = true

          var i = 0
          while (i < ss.length) {
            ss(i) = ss(i).simplify(pending)
            ss(i) match {
              case t @ Const(Throw(_)) =>
                return forward(t.asInstanceOf[Stitch[Seq[T]]])
              case Const(_) =>
              case _ => satisfied = false
            }
            i += 1
          }

          if (satisfied) {
            val result = ss.asInstanceOf[ArrayBuffer[T]]
            var i = 0
            while (i < ss.length) {
              ss(i) match {
                case Const(Return(t)) => result(i) = t.asInstanceOf[T]
                case _ => scala.sys.error("stitch bug")
              }
              i += 1
            }
            forward(Stitch.value(result))
          } else this

        case _ =>
          self.simplify(pending) match {
            case s @ Const(Throw(_)) =>
              forward(s.asInstanceOf[Stitch[Seq[T]]])

            case Const(Return(ts)) =>
              var i = 0
              while (i < ts.length) {
                ts(i) match {
                  case t @ Throw(_) =>
                    return forward(Const(t).asInstanceOf[Stitch[Seq[T]]])
                  case _ =>
                }
                i += 1
              }

              val result = new ArrayBuffer[T](ts.length)
              i = 0
              while (i < ts.length) {
                ts(i) match {
                  case Return(t) => result += t
                  case _ => scala.sys.error("stitch bug")
                }
                i += 1
              }
              forward(Stitch.value(result))

            case self =>
              this.self = self
              this
          }
      }
    }