小编mXa*_*aln的帖子

将 Single<List<Maybe<Book>>> 转换为 Single<List<Book>>

有人可以帮忙吗?

我有这些功能

fun getBooks(): Single<List<Book>> {
    return getCollections()
        .map {
            it.map(::collectonToBook)
        }
}

fun getCollections(): Single<List<Collection>> {
   return db.fetchCollections()
       .filter(::isBook)
}

fun collectonToBook(collection: Collection): Maybe<Book> {
    return collection.toBook()
}
            
Run Code Online (Sandbox Code Playgroud)

问题是 getBooksSingle<List<Maybe<Book>>>在我需要时返回Single<List<Book>>。我可以在流中执行此操作而不调用blockingGet吗?

kotlin rx-kotlin rx-java2

1
推荐指数
1
解决办法
52
查看次数

标签 统计

kotlin ×1

rx-java2 ×1

rx-kotlin ×1