fork download
  1. import java.util.*;
  2. import java.util.function.*;
  3. import java.util.stream.*;
  4.  
  5. class Ideone {
  6. public static final Function<List<IntUnaryOperator>, UnaryOperator<List<Integer>>> mapper
  7. = opList -> argList -> argList.stream()
  8. .flatMap(i -> opList.stream()
  9. .collect(Collector.of(
  10. ArrayList<IntUnaryOperator>::new,
  11. (a, b) -> a.add(a.isEmpty() ? b : a.get(a.size() - 1).andThen(b)),
  12. (a, b) -> { throw new UnsupportedOperationException(); }
  13. ))
  14. .stream()
  15. .map(op -> op.applyAsInt(i))
  16. )
  17. .collect(Collectors.toList());
  18.  
  19. public static void main(String[] args) {
  20. List<Integer> list = mapper.apply(List.of(x -> x, x -> x + 1, x -> x * x)).apply(List.of(1, 2));
  21. System.out.println(list);
  22. }
  23. }
Success #stdin #stdout 0.08s 34320KB
stdin
Standard input is empty
stdout
[1, 2, 4, 2, 3, 9]