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)
问题在于,由于类型擦除,该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)
归档时间: |
|
查看次数: |
2505 次 |
最近记录: |