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

org.opensearch.migrations.Utils Maven / Gradle / Ivy

There is a newer version: 0.1.0.17
Show newest version
package org.opensearch.migrations;

import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.stream.Collector;
import java.util.stream.Collectors;

public class Utils {
    private Utils() {}

    /**
     * See https://en.wikipedia.org/wiki/Fold_(higher-order_function)
     */
    public static  Collector foldLeft(
        final B seedValue,
        final BiFunction f
    ) {
        return Collectors.collectingAndThen(
            Collectors.reducing(Function.identity(), a -> b -> f.apply(b, a), Function::andThen),
            finisherArg -> finisherArg.apply(seedValue)
        );
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy