All Projects → akarnokd → Rxjavajdk8interop

akarnokd / Rxjavajdk8interop

Licence: apache-2.0
RxJava 2/3 interop library for supporting Java 8 features such as Optional, Stream and CompletableFuture [discontinued]

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Rxjavajdk8interop

Rxjavaextensions
RxJava 2.x & 3.x extra sources, operators and components and ports of many 1.x companion libraries.
Stars: ✭ 662 (+845.71%)
Mutual labels:  rxjava, reactive-streams, extensions
rxjava2-http
Transmit RxJava2 Flowable over http with non-blocking backpressure
Stars: ✭ 19 (-72.86%)
Mutual labels:  stream, rxjava, reactive-streams
Rxjava2 Extras
Utilities for use with RxJava 2
Stars: ✭ 167 (+138.57%)
Mutual labels:  rxjava, stream, reactive-streams
Rxjavainterop
Library to convert between RxJava 1.x and 2.x/3.x reactive types, schedulers and resource handles.
Stars: ✭ 856 (+1122.86%)
Mutual labels:  rxjava, reactive-streams, extensions
RxLoading
RxJava library for showing a loading (i.e. progress bar) state while waiting for async data with minimal effort and advanced options.
Stars: ✭ 49 (-30%)
Mutual labels:  stream, rxjava
Rxjavareactivestreams
Adapter between RxJava and ReactiveStreams
Stars: ✭ 227 (+224.29%)
Mutual labels:  rxjava, reactive-streams
Rhub
Reactive Event Hub
Stars: ✭ 66 (-5.71%)
Mutual labels:  rxjava, reactive-streams
reactor-go
A golang implementation for reactive-streams.
Stars: ✭ 48 (-31.43%)
Mutual labels:  rxjava, reactive-streams
ProxerAndroid
The official Android App of Proxer.Me
Stars: ✭ 105 (+50%)
Mutual labels:  stream, rxjava
Reactive
Reactive: Examples of the most famous reactive libraries that you can find in the market.
Stars: ✭ 256 (+265.71%)
Mutual labels:  rxjava, stream
Rxjava2 Jdbc
RxJava2 integration with JDBC including Non-blocking Connection Pools
Stars: ✭ 360 (+414.29%)
Mutual labels:  rxjava, reactive-streams
Hivemq Mqtt Client
HiveMQ MQTT Client is an MQTT 5.0 and MQTT 3.1.1 compatible and feature-rich high-performance Java client library with different API flavours and backpressure support
Stars: ✭ 402 (+474.29%)
Mutual labels:  rxjava, reactive-streams
Ixjava
Iterable Extensions for Java 6+
Stars: ✭ 210 (+200%)
Mutual labels:  rxjava, stream
live-stream-media-source-extensions
Live stream h264 encoded mp4 video on media source extensions using ffmpeg, node.js, socket.io, and express. Works in chrome, firefox, safari, and android. Not iOS compatible. Work has moved to mse-live-player repo =>
Stars: ✭ 24 (-65.71%)
Mutual labels:  stream, extensions
Rxdownloader
Demo of Downloading Songs/Images through Android Download Manager using RxJava2
Stars: ✭ 166 (+137.14%)
Mutual labels:  rxjava, stream
Rsocket Java
Java implementation of RSocket
Stars: ✭ 2,099 (+2898.57%)
Mutual labels:  rxjava, stream
Rxjava
RxJava – Reactive Extensions for the JVM – a library for composing asynchronous and event-based programs using observable sequences for the Java VM.
Stars: ✭ 45,607 (+65052.86%)
Mutual labels:  rxjava, reactive-streams
Autodispose
Automatic binding+disposal of RxJava streams.
Stars: ✭ 3,209 (+4484.29%)
Mutual labels:  rxjava, reactive-streams
Grpc By Example Java
A collection of useful/essential gRPC Java Examples
Stars: ✭ 709 (+912.86%)
Mutual labels:  rxjava, stream
Spring Reactive Sample
Spring 5 Reactive playground
Stars: ✭ 867 (+1138.57%)
Mutual labels:  rxjava, reactive-streams

RxJavaJdk8Interop

⚠️ Discontinued

The features of this library (and more) have been integrated into RxJava 3 proper starting with version 3.0.0-RC7.


codecov.io Maven Central

RxJava 3.x: RxJava 3.x

RxJava 3 interop library for supporting Java 8 features such as Optional, Stream and CompletableFuture.

Release

RxJava 3

compile 'com.github.akarnokd:rxjava3-jdk8-interop:3.0.0-RC6'

RxJava 2

compile 'com.github.akarnokd:rxjava2-jdk8-interop:0.3.7'

Examples

Javadocs: https://akarnokd.github.com/RxJavaJdk8Interop/javadoc/index.html

The main entry points are:

  • FlowableInterop
  • ObservableInterop
  • SingleInterop
  • MaybeInterop
  • CompletableInterop

Stream to RxJava

Note that java.util.stream.Stream can be consumed at most once and only synchronously.

Stream<T> stream = ...

Flowable<T> flow = FlowableInterop.fromStream(stream);

Observable<T> obs = ObservableInterop.fromStream(stream);

Optional to RxJava

Optional<T> opt = ...

Flowable<T> flow = FlowableInterop.fromOptional(opt);

Observable<T> obs = ObservableInterop.fromOptional(opt);

CompletionStage to RxJava

Note that cancelling the Subscription won't cancel the CompletionStage.

CompletionStage<T> cs = ...

Flowable<T> flow = FlowableInterop.fromFuture(cs);

Observable<T> flow = ObservableInterop.fromFuture(cs);

Using Stream Collectors

Flowable.range(1, 10)
.compose(FlowableInterop.collect(Collectors.toList()))
.test()
.assertResult(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));

Return the first/single/last element as a CompletionStage

CompletionStage<Integer> cs = Flowable.just(1)
.delay(1, TimeUnit.SECONDS)
// return first
.to(FlowableInterop.first());

// return single
// .to(FlowableInterop.single());

// return last
// .to(FlowableInterop.last());

cs.whenComplete((v, e) -> {
   System.out.println(v);
   System.out.println(e);
});

Return the only element as a CompletionStage

Single

CompletionStage<Integer> cs = Single.just(1)
.delay(1, TimeUnit.SECONDS)
.to(SingleInterop.get());

cs.whenComplete((v, e) -> {
   System.out.println(v);
   System.out.println(e);
});

Maybe

CompletionStage<Integer> cs = Maybe.just(1)
.delay(1, TimeUnit.SECONDS)
.to(MaybeInterop.get());

cs.whenComplete((v, e) -> {
   System.out.println(v);
   System.out.println(e);
});

Await completion as CompletionStage

Completable

CompletionStage<Void> cs = Completable.complete()
.delay(1, TimeUnit.SECONDS)
.to(CompletableInterop.await());

cs.whenComplete((v, e) -> {
   System.out.println(v);
   System.out.println(e);
});

Return the first/last element optionally

This is a blocking operation

Optional<Integer> opt = Flowable.just(1)
.to(FlowableInterop.firstElement());

System.out.println(opt.map(v -> v + 1).orElse(-1));

Convert to Java Stream

This is a blocking operation. Closing the stream will cancel the RxJava sequence.

Flowable.range(1, 10)
.to(FlowableInterop.toStream())
.parallel()
.map(v -> v + 1)
.forEach(System.out::println);

FlatMap Java Streams

Note that since consuming a stream is practically blocking, there is no need for a maxConcurrency parameter.

Flowable.range(1, 5)
.compose(FlowableInterop.flatMapStream(v -> Arrays.asList(v, v + 1).stream()))
.test()
.assertResult(1, 2, 2, 3, 3, 4, 4, 5, 5, 6);

Map based on Java Optional

Flowable.range(1, 5)
.compose(FlowableInterop.mapOptional(v -> v % 2 == 0 ? Optional.of(v) : Optional.empty()))
.test()
.assertResult(2, 4);
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].