DurianRx unifies RxJava's Observable with Guava's ListenableFuture. If you happen to be using SWT as a widget toolkit, then you'll want to look at DurianSwt as well.
Observable<SomeType> observable = someObservable();
ListenableFuture<SomeType> future = someFuture();
Rx.subscribe(observable, val -> doSomething(val));
Rx.subscribe(future, val -> doSomething(val));
It also provides reactive getters, a simple abstraction for piping data which allows access via T get()
or Observable<T> asObservable()
.
RxBox<Point> mousePos = RxBox.of(new Point(0, 0));
this.addMouseListener(e -> mousePos.set(new Point(e.x, e.y)));
Rectangle hotSpot = new Rectangle(0, 0, 10, 10)
RxGetter<Boolean> isMouseOver = mousePos.map(hotSpot::contains);
Debugging an error which involves lots of callbacks can be difficult. To make this easier, DurianRx includes a tracing capability, which makes this task easier.
// anytime an error is thrown in an Rx callback, the stack trace of the error
// will be wrapped by the stack trace of the original subscription
DurianPlugins.set(RxTracingPolicy.class, new LogSubscriptionTrace()).
Lastly, DurianRx provides convenience classes for manipulating Guava's immutable collections inside reactive containers, such as RxSet<T> extends RxBox<ImmutableSet<T>>
, which can be used as such:
public void mouseClicked(MouseEvent e) {
rxMouseOver.get().ifPresent(cell -> {
Set<Integer> currentSelection = rxSelection.get();
if (e.isControlDown()) {
// control => toggle mouseOver item in selection
if (currentSelection.contains(cell)) {
rxSelection.remove(cell);
} else {
rxSelection.add(cell);
}
} else {
// no control => set selection to mouseOver
rxSelection.set(Collections.singleton(cell));
}
});
}
...
Rx.subscribe(rxSelection, set -> {
// take some action in response to
// selection change
});
Perhaps most useful of all is the Immutables utility class, which helps with all kinds of manipulations of Guava's immmutable collections.
DurianRx's only requirements are Guava, RxJava, and Durian.
- Many thanks to RxJava and Guava.
- Stream Collectors for Guava collections inspired by Maciej Miklas's blog post.
- Formatted by spotless, as such.
- Bugs found by findbugs, as such.
- OSGi metadata generated by JRuyi's [osgibnd-gradle-plugin] (https://github.com/jruyi/osgibnd-gradle-plugin), which leverages Peter Kriens' bnd.
- Scripts in the
.ci
folder are inspired by Ben Limmer's work. - Built by gradle.
- Tested by junit.
- Maintained by DiffPlug.