scala EitherT折叠和标识

时间:2019-05-13 18:44:18

标签: scala

我有以下代码:

private def processRequest(
      serviceName: String,
      httpMethod: String,
      request: HttpServiceResult[IncomingHttpRequest]
  ): Future[HttpResponse] =
    request
      .flatMap { incomingRequest =>
        .. do something here ..

        val responseDTO: Future[ResponseDTO] = database.getResponseByService(serviceName, httpMethod)

        val httpResponse: Future[HttpResponse] = responseDTO
          .map(
            dto => HttpResponse(status = dto.responseCode, entity = dto.responsePayload)
          )

        EitherT.pure[Future, HttpError](httpResponse)
      }
      .fold(
        error => {
          logger.warn(
            LoggingMessage(
              requestId = error.requestId,
              message = s"Error when processing request for inbound recon replay: ${error.message}"
            )
          )
          HttpResponse(status = 200, entity = HttpEntity(s"err:${error.message}"))
        },
        identity
      )

我猜想identity代表了httpResponse,实际上是Future [HttpResponse],但是它只是一个HttpResponse,我该如何从Future [HttpResponse]中解开HttpResponse

0 个答案:

没有答案