【发布时间】:2018-01-06 16:43:21
【问题描述】:
我有无法解决的问题。我正在尝试使用 Kotlin 将多个 Singles 压缩为一个,而我提供的第二个参数都不适合。
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) }
【问题讨论】:
-
函数的Java定义为
Function<? super Object[], R>,所以需要在Kotlin中表示Object[]。 -
我会尝试用 Java 编写这个文件,不使用 lambda,然后使用
Convert Java to Kotlin将其转换为 Kotlin