使用Retrofit rxjava concatWith时堆栈溢出

使用Retrofit rxjava concatWith时堆栈溢出,第1张

使用Retrofit rxjava concatWith时堆栈溢出

因此,鉴于我回答了您引用的原始问题,我可能也应该尝试回答这种情况。:)

这是我最初的寻呼答案的另一种有效(且可能更简单)的替代方法,因为我已经在军械库中开发了更多的Rx技巧。:)(以java8 lambda样式的伪代码完成):

Observable.range(Integer.MAX_VALUE)    // Get each page in order.    .concatMap(page -> getResults(page))    // Take every result up to and including the one where the next page index is null.    .takeUntil(result -> result.next == null)    // Add each output to a list builder. I'm using Guava's ImmutableList, but you could    // just as easily use a regular ArrayList and avoid having to map afterwards. I just    // personally prefer outputting an immutable data structure, and using the builder    // is natural for this.    //    // Also, if you wanted to have the observable stream the full output at each page,    // you could use collect instead of reduce. Note it has a slightly different syntax.     .reduce(        ImmutableList.<ResponseObject>builder(),        (builder, response) -> builder.addAll(response.results))    // Convert list builder to one List<ResponseObject> of all the things.    .map(builder -> builder.build())    .subscribe(results -> {  });


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5054509.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-16
下一篇 2022-11-15

发表评论

登录后才能评论

评论列表(0条)

保存