Feature Request: Add unfold construct to Flowable/Observable
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 35/100
- issue の種類
- 機能追加
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
- 技術スタック
- java
調査の方向性
まず既存の Flowable.create、Flowable.generate、Flowable.fromFuture のエントリーポイントを読み、それらのバックプレッシャーと非同期動作を比較してください。提案されている Flowable.unfold、Flowable.unfoldMaybe、および Observable の対応するものを確認し、実装とテストを検討する前に、提供された range の例を使って完了、需要、非同期動作を定義してください。
索引モデルが issue の本文から書いたものです。
説明
Version 3.1.4
Scala as of 2.13 and Akka (another reactive framework) have added various unfold patterns, and I'm finding a need for this currently. Here's the use case - pagination of responses to a "cursor"-like REST api.
Essentially, I'd like to make a Flowable that makes requests to get another page - where it starts without a "continuation" parameter, and keeps making requests (honoring backpressure) until the response comes without a "continuation".
Flowable.create doesn't seem to deal with the backpressure well, and Flowable.generate is blocking, which seems disappointing as Flowable.fromFuture is great at dealing with async http clients.
This unfold pattern seems to offer what would be very helpful to the cause - where a new request isn't made until the subscriber asks for more, and the termination state is known from some inspection of the previous element in the feed (the http response, or the json parsing of it).
Here's a stab of making these using RxJava constructs; it would be nice if Flowable.unfold and Flowable.unfoldMaybe (and Observable too) could be added to RxJava itself.
import java.util.Optional;
import java.util.function.Function;
import io.reactivex.rxjava3.core.Flowable;
import io.reactivex.rxjava3.core.Maybe;
import io.reactivex.rxjava3.core.MaybeSource;
public class Unfold {
public static class Pair<L, R> {
private final L left;
private final R right;
public Pair(L left, R right) {
this.left = left;
this.right = right;
}
public L getLeft() {
return left;
}
public R getRight() {
return right;
}
}
public static <S, E> Flowable<E> flowableUnfold(S state, Function<S, Optional<Pair<S, E>>> generator) {
return Flowable.defer(() -> Flowable.fromOptional(generator.apply(state)))
.flatMap(pair -> Flowable.just(pair.getRight())
.concatWith(flowableUnfold(pair.getLeft(), generator)));
}
public static <S, E> Flowable<E> flowableUnfoldMaybe(S state, Function<S, ? extends MaybeSource<Pair<S, E>>> generator) {
return Flowable.defer(() -> Flowable.fromMaybe(generator.apply(state)))
.flatMap(pair -> Flowable.just(pair.getRight())
.concatWith(flowableUnfoldMaybe(pair.getLeft(), generator)));
}
}
And some scala to test it
@RunWith(classOf[JUnitRunner])
class UnfoldTest extends AnyFlatSpec with Matchers {
"flowableUnfold" should "work with range of 0 to 10" in {
val flowable = Unfold.flowableUnfold[(Int, Int), Int]((0, 10), {
case (start: Int, end: Int) if start < end =>
Option(new Pair(start + 1 -> end, start)).asJava
case _ => None.asJava
})
flowable.toList.blockingGet().asScala shouldBe (0 until 10)
}
"flowableUnfoldMaybe" should "work with range of 0 to 10" in {
val flowable = Unfold.flowableUnfoldMaybe[(Int, Int), Int]((0, 10), {
case (start: Int, end: Int) if start < end =>
Maybe.fromCallable(() => new Pair(start + 1 -> end, start))
case _ => Maybe.empty()
})
flowable.toList.blockingGet().asScala shouldBe (0 until 10)
}
}
- 主要言語
- Java
- スター
- 48.2k
- フォーク
- 7.6k
- 平均マージ
- 3時間 2分
- マージ済み PR(30日)
- 27
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
ReactiveX/RxJava のほかの issue
-
4.x Streamable Test-Failures
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
メンテナーはふだん 1 日以内に返信
-
4.x AI Enhancement Streamable
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
ReactiveX/RxJava#8299 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
4.x: FlowableBufferTest > longTimeAction() FAILED再び着手できるかも @akarnokd が 81 日前に担当しましたが、オープン中のプルリクエストはありません。 オープン4.x Test-Failures
ReactiveX/RxJava#8280 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
4.x Discussion
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
メンテナーはふだん 1 日以内に返信
-
4.x PR welcome Test Test-Failures
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
ReactiveX/RxJava#8075 · コメント 4 件 ·
メンテナーはふだん 1 日以内に返信
ReactiveX/RxJava の issue をすべて見る
似ている issue
-
breaking change bug needs human review not ready priority medium size S
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
martin-francois/symphony-trello#1193 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Mend: dependency security vulnerability
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
メンテナーはふだん 1 日以内に返信
-
status: waiting-for-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
spring-projects/spring-framework#37614 ·
メンテナーはふだん 1 日以内に返信