in src/main/scala/com/twitter/stitch/Arrow.scala [480:529]
override def run[T2 <: (T, C), V](
t2s: ArrayBuffer[Try[T2]],
ls: ArrayBuffer[Locals],
tail: Arrow[U, V]
): Stitch[ArrayBuffer[Try[V]]] = {
var hasReturn = false
var hasCommonContext = true
var commonContext = null.asInstanceOf[C]
var i = 0
while (hasCommonContext && i < t2s.length) {
t2s(i) match {
case Return((_, c: C @unchecked)) =>
hasReturn = true
if (commonContext == null) commonContext = c
else if (c != commonContext) hasCommonContext = false
case _ =>
}
i += 1
}
if (hasReturn) {
if (hasCommonContext) {
val ts = t2s.asInstanceOf[ArrayBuffer[Try[T]]]
var i = 0
while (i < ts.length) {
t2s(i) match {
case Return((t, _)) => ts(i) = Return(t)
case _ =>
}
i += 1
}
Call.run(ts, gf(commonContext), ls, tail)
} else { // !hasCommonContext
val ss = t2s.asInstanceOf[ArrayBuffer[Stitch[U]]]
var i = 0
while (i < t2s.length) {
ss(i) = t2s(i) match {
case Return((t, c)) => Stitch.call(t, gf(c))
case t => Stitch.const(t.asInstanceOf[Try[U]])
}
i += 1
}
Stitch.transformSeq(ss, ls, tail)
}
} else { // !hasReturn
tail.run(t2s.asInstanceOf[ArrayBuffer[Try[U]]], ls)
}
}