Feature Request: Add unfold construct to Flowable/Observable
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 35/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Bastante claro
- Estado de actividad
- Estancado
- Stack tecnológico
- java
- Área
- backend-api-design
Línea de trabajo
Comienza leyendo los puntos de entrada existentes Flowable.create, Flowable.generate y Flowable.fromFuture, y compara su comportamiento de backpressure y asíncrono. Revisa las propuestas Flowable.unfold, Flowable.unfoldMaybe y sus equivalentes de Observable; después, usa los ejemplos de range proporcionados para definir la finalización, la demanda y el comportamiento asíncrono antes de considerar la implementación y las pruebas.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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)
}
}
- Lenguaje dominante
- Java
- Estrellas
- 48.2k
- Forks
- 7.6k
- Merge medio
- 3 h 2 min
- PR fusionados (30 d)
- 27
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de ReactiveX/RxJava
-
4.x Streamable Test-Failures
Dificultad 4/5 3-5 días Aptitud para principiantes 45/100
Los mantenedores suelen responder en 1 día
-
4.x AI Enhancement Streamable
Dificultad 4/5 3-5 días Aptitud para principiantes 45/100
ReactiveX/RxJava#8299 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
4.x: FlowableBufferTest > longTimeAction() FAILEDQuizá libre de nuevo @akarnokd la tomó hace 81 días y no hay ningún pull request abierto. Abierto4.x Test-Failures
ReactiveX/RxJava#8280 · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
4.x Discussion
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
Los mantenedores suelen responder en 1 día
-
4.x PR welcome Test Test-Failures
Dificultad 4/5 3-5 días Aptitud para principiantes 45/100
ReactiveX/RxJava#8075 · 4 comentarios ·
Los mantenedores suelen responder en 1 día
Todos los issues de ReactiveX/RxJava
Issues similares
-
[BUG] micronaut-serde-oracle-jdbc-json brings a second OJDBC driver onto the runtime classpathPosiblemente ocupada @ZARAYACH la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
micronaut-projects/micronaut-serialization#1494 · 4 comentarios ·
Los mantenedores suelen responder en 2 días
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 73/100
Los mantenedores suelen responder en 2 días
-
code-health feature/sync OS/Android QA/Test-Plan-Specified QA/Yes
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
brave/brave-browser#60327 ·
Los mantenedores suelen responder en 1 día
-
Type: Bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
it-at-m/raumreservierung#383 ·
Los mantenedores suelen responder en 3 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
aws/context-ontology-accelerator#325 ·
Los mantenedores suelen responder en 1 día