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

functionalj.stream.LongStreamElementProcessor Maven / Gradle / Ivy

There is a newer version: 1.0.17
Show newest version
package functionalj.stream;

import java.util.function.ToLongFunction;

import lombok.val;

public interface LongStreamElementProcessor {
    void processElement (long index, long element);
    T    processComplete(long count);
    
    default  StreamElementProcessor of(ToLongFunction mapper) {
        return new StreamElementProcessor() {
            @Override
            public void processElement(long index, S source) {
                val element = mapper.applyAsLong(source);
                LongStreamElementProcessor.this.processElement(index, element);
            }
            @Override
            public T processComplete(long count) {
                return LongStreamElementProcessor.this.processComplete(count);
            }
        };
    }
}