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

fun.mike.flapjack.pipeline.lab.ReduceOutputChannel Maven / Gradle / Ivy

There is a newer version: 0.0.15
Show newest version
package fun.mike.flapjack.pipeline.lab;

import java.util.Optional;
import java.util.function.BiFunction;

import fun.mike.record.alpha.Record;

public class ReduceOutputChannel implements OutputChannel {
    private final T identityValue;
    private final BiFunction reducer;
    private T reducedValue;

    public ReduceOutputChannel(T identityValue, BiFunction reducer) {
        this.identityValue = identityValue;
        this.reducer = reducer;
        this.reducedValue = identityValue;
    }

    @Override
    public Optional put(int number, String line, Record value) {
        try {
            reducedValue = reducer.apply(reducedValue, value);
            return Optional.empty();
        } catch (Exception ex) {
            return Optional.of(OutputPipelineError.build(number, line, value, ex));
        }
    }

    public T getValue() {
        return reducedValue;
    }

    @Override
    public void close() {}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy