RxJava 2.0和Kotlin Single.zip()以及单曲列表

Efk*_*fka 5 kotlin rx-java rx-kotlin

我有我无法解决的问题。我试图使用Kotlin将.zip(List,)多个Singles合并为一个,而我提供的Function都不适合作为第二个参数。

    fun getUserFriendsLocationsInBuckets(token: String) {
    roomDatabase.userFriendsDao().getUserFriendsDtosForToken(token).subscribe(
            { userFriends: List<UserFriendDTO> ->
                Single.zip(getLocationSingleForEveryUser(userFriends),
                        Function<Array<List<Location>>, List<Location>> { t: Array<List<Location>> -> listOf<Location>() })
            },
            { error: Throwable -> }
    )
}

private fun getLocationSingleForEveryUser(userFriends: List<UserFriendDTO>): List<Single<List<Location>>> =
        userFriends.map { serverRepository.locationEndpoint.getBucketedUserLocationsInLast24H(it.userFriendId) }
Run Code Online (Sandbox Code Playgroud)

Android Studio错误

mar*_*one 5

问题在于,由于类型擦除,该zipper函数的参数类型未知。如您所见zip

public static <T, R> Single<R> zip(final Iterable<? extends SingleSource<? extends T>> sources, Function<? super Object[], ? extends R> zipper)
Run Code Online (Sandbox Code Playgroud)

您必须将其Any用作数组的输入,并强制转换为所需的每个数组:

roomDatabase.userFriendsDao().getUserFriendsDtosForToken(token).subscribe(
        { userFriends: List<UserFriendDTO> ->
            Single.zip(
                    getLocationSingleForEveryUser(userFriends),
                    Function<Array<Any>, List<Location>> { t: Array<Any> -> listOf<Location>() })
        },
        { error: Throwable -> }
)
Run Code Online (Sandbox Code Playgroud)