代码之家  ›  专栏  ›  技术社区  ›  Jerry

“单声道。不能使用提供的参数调用and()

  •  0
  • Jerry  · 技术社区  · 9 年前

    我正在尝试运行位于 here . 然而,我看到一个

    Error:(38, 22) Kotlin: None of the following functions can be called with the arguments supplied: public final fun and(p0: ((Subscriber<in Any!>!) -> Unit)!): Mono<Void!>! defined in reactor.core.publisher.Mono public final fun and(p0: Publisher<*>!): Mono<Void!>! defined in reactor.core.publisher.Mono

    在里面 ApiHandler.kt 中的类 buildResponse 功能:

    internal class ApiHandler(val geoLocationService: GeoLocationService, val sunriseSunsetService: SunriseSunsetService,
                          val errorHandler: ErrorHandler) {
    
        private companion object {
            const val ADDRESS = "address"
        }
    
        internal fun getLocation(request: ServerRequest) =
            request.pathVariable(ADDRESS).toMono()
                    .transform(this::buildResponse)
                    .transform(this::serverResponse)
                    .onErrorResume(errorHandler::throwableError)!!
    
        internal fun postLocation(request: ServerRequest) =
            request.extract<LocationRequest>()
                    .map(LocationRequest::address)
                    .transform(this::buildResponse)
                    .transform(this::serverResponse)
                    .onErrorResume(errorHandler::throwableError)!!
    
        internal fun buildResponse(address: Mono<String>) =
            address.transform(geoLocationService::fromAddress)
                    .and(this::sunriseSunset, ::LocationResponse)
    
        internal fun sunriseSunset(geographicCoordinates: GeographicCoordinates) =
            geographicCoordinates.toMono().transform(sunriseSunsetService::fromGeographicCoordinates)
    
        internal fun serverResponse(locationResponseMono: Mono<LocationResponse>): Mono<ServerResponse> =
            locationResponseMono.flatMap { ok() withBody it }
    }
    

    我猜想自编写此代码以来,Spring API已经发生了更改,但我不知道要更改什么 .and(...) 到

    1 回复  |  直到 9 年前
        1
  •  1
  •   Brian Clozel    9 年前

    我认为这与3.1.0中反应堆核心API的变化有关。

    Mono.and() 不再是返回元组的运算符,但它现在只关心完成信号( Mono<Void> ). 你应该换掉它 and() 带有 zip 或 zipWith 操作员,如中所示 the Reactor release notes .