1
I am reading the documentation of this bookstore that is in the title.
I want to implement a method that returns a composition of functions, if I not by arguments must return the identity function, if 1 must return only the function, if n>1 must return to all functions, as the example:
1 IntUnaryOperator[] functions = {
2 compose(),
3 compose(x -> x+1),
4 compose(x -> x*2, x -> x+1),
5 compose(x -> x+1, x -> x*2),
6 compose(x -> x+1, x -> x*2, x -> x+1)
7 };
8 for (IntUnaryOperator f : functions) System.out.println(f.applyAsInt(1));
9 // Resultado esperado: 1, 2, 3, 4, 5
I imagine I should start like this, but I don’t know how to use both functions consistently yet, I need an intuition of how to proceed.
import java.util.function.IntUnaryOperator;
public class IntOperatorsUtil {
public static IntUnaryOperator compose(IntUnaryOperator... functions) {
thank you very much, I got interested in the solution and I will study about stream
– Pirategull