All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.reactfx.DistinctStream Maven / Gradle / Ivy

There is a newer version: 2.0-M5
Show newest version
package org.reactfx;

import java.util.Objects;


class DistinctStream extends EventStreamBase {
    static final Object NONE = new Object();
    private final EventStream input;
    private Object previous = NONE;

    public DistinctStream(EventStream input) {
        this.input = input;
    }

    @Override
    protected Subscription observeInputs() {
        return input.subscribe(value -> {
            Object prevToCompare = previous;
            previous = value;
            if (!Objects.equals(value, prevToCompare)) {
                emit(value);
            }
        });
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy