fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.function.BiFunction;
  4. import java.util.function.UnaryOperator;
  5. import java.util.stream.Stream;
  6.  
  7. class Price {
  8. private int value;
  9.  
  10. public Price(int value) {
  11. this.value = value;
  12. }
  13.  
  14. public int getValue() {
  15. return value;
  16. }
  17. }
  18.  
  19. class Ideone
  20. {
  21. public static void main (String[] args) throws java.lang.Exception
  22. {
  23. BiFunction<Price, Integer, Price> WholesalePrice = (t, advantage) -> new Price(t.getValue() + advantage);
  24. UnaryOperator<Price> DoublePrice = t -> new Price(t.getValue() * 2);
  25.  
  26. Stream.of(new Price(120))
  27. .map(DoublePrice)
  28. .map(x -> WholesalePrice.apply(x, 80))
  29. .map(DoublePrice)
  30. .map(x -> WholesalePrice.apply(x, 200))
  31. .mapToInt(Price::getValue)
  32. .forEach(System.out::println);
  33. }
  34. }
Success #stdin #stdout 0.2s 320704KB
stdin
Standard input is empty
stdout
840