Returns composition of given functions. - Java Lambda Stream

Java examples for Lambda Stream:Function

Description

Returns composition of given functions.

Demo Code


//package com.java2s;

import java.util.function.Function;

public class Main {
    /** Returns composition of given functions. Given 0 or more functions,
     *  returns a new function that is a composition of them, in order. The functions
     *  must all map their argument to an output of the SAME type (i.e., Function<T,T>).
     *///w  w w .  j  ava  2s . co  m
    public static <T> Function<T, T> composeAll(Function<T, T>... functions) {
        Function<T, T> result = Function.identity();
        for (Function<T, T> f : functions) {
            result = result.compose(f);
        }
        return (result);
    }
}

Related Tutorials