org.reactfx.AccumulatingStream Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of richtextfx Show documentation
Show all versions of richtextfx Show documentation
FX-Text-Area for formatted text and other special effects.
package org.reactfx;
import java.util.function.BiFunction;
import java.util.function.Function;
/**
* See {@link EventStream#accumulate(BiFunction, Function)}
*/
class AccumulatingStream extends EventStreamBase {
private final EventStream input;
private final Function super T, ? extends U> initialTransformation;
private final BiFunction super U, ? super T, ? extends U> reduction;
private boolean hasEvent = false;
private U event = null;
public AccumulatingStream(
EventStream input,
Function super T, ? extends U> initial,
BiFunction super U, ? super T, ? extends U> reduction) {
this.input = input;
this.initialTransformation = initial;
this.reduction = reduction;
}
@Override
protected final Subscription observeInputs() {
return input.subscribe(i -> {
event = hasEvent
? reduction.apply(event, i)
: initialTransformation.apply(i);
hasEvent = true;
emit(event);
});
}
}