def traverse[A]()

in fapi-client-core/src/main/scala/com/gu/facia/api/Response.scala [66:78]


  def traverse[A](responses: List[Response[A]])(implicit ec: ExecutionContext): Response[List[A]] = Response {
    Future.traverse(responses)(_.asFuture).flatMap { eithers =>
      @tailrec
      def loop(rs: List[Either[ApiError, A]], acc: List[A]): Response[List[A]] = {
        if (rs.isEmpty) Response.Right(acc.reverse)
        else rs.head match {
          case Left(apiErr) => Response.Left(apiErr)
          case Right(a) => loop(rs.tail, a :: acc)
        }
      }
      loop(eithers, Nil).asFuture
    }
  }