File tree Expand file tree Collapse file tree
modules/src/main/java/com/platzi/functional/_11_composition Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package com .platzi .functional ._11_composition ;
2+
3+ import java .util .function .Function ;
4+
5+ public class MathOperations2 {
6+ public static void main (String [] args ) {
7+ Function <Integer , Integer > multiplyBy3 = x -> {
8+ System .out .println ("Multiplicando x: " + x + " por 3" );
9+ return x * 3 ;
10+ };
11+
12+ Function <Integer , Integer > add1MultiplyBy3 =
13+ multiplyBy3 .compose (y -> {
14+ System .out .println ("Le agregare 1 a: " + y );
15+ return y + 1 ;
16+ });
17+
18+ Function <Integer , Integer > andSquare =
19+ add1MultiplyBy3 .andThen (x -> {
20+ System .out .println ("Estoy elevando " + x + " al cuadrado" );
21+ return x * x ;
22+ });
23+
24+ System .out .println (
25+ add1MultiplyBy3 .apply (5 )
26+ );
27+
28+ System .out .println (andSquare .apply (3 ));
29+ }
30+ }
You can’t perform that action at this time.
0 commit comments