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

io.atleon.core.AloGroupedFlux Maven / Gradle / Ivy

package io.atleon.core;

import org.reactivestreams.Publisher;
import reactor.core.publisher.Flux;
import reactor.core.publisher.GroupedFlux;
import reactor.core.publisher.SynchronousSink;

import java.util.function.BiConsumer;
import java.util.function.Function;

/**
 * A wrapper around Project Reactor's {@link GroupedFlux} for keys of type K and for Alo elements
 * containing data of type T. The goal of this wrapping is to make the handling of Alo more
 * transparent such that clients need only define pipelines in terms of T versus Alo (of type T)
 *
 * @param  The type of key for this AloFlux is grouped to
 * @param  The type of elements contained in the Alo's of this reactive Publisher
 */
public class AloGroupedFlux extends AloFlux {

    private final K key;

    private AloGroupedFlux(Flux> flux, K key) {
        super(flux);
        this.key = key;
    }

    static  AloGroupedFlux create(GroupedFlux> groupedFlux) {
        return new AloGroupedFlux<>(groupedFlux, groupedFlux.key());
    }

    static  AloGroupedFlux
    create(GroupedFlux> groupedFlux, BiConsumer, SynchronousSink>> mappingHandler) {
        return new AloGroupedFlux<>(groupedFlux.handle(mappingHandler), groupedFlux.key());
    }

    public  AloGroupedFlux
    transformGrouped(Function, ? extends Publisher>> transformer) {
        return new AloGroupedFlux<>(AloFlux.toFlux(transformer.apply(this)), key);
    }

    public K key() {
        return key;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy