Skip to content

Commit 57e08a6

Browse files
committed
Agregando el ejemplo para operaciones
1 parent 02682dc commit 57e08a6

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
}

0 commit comments

Comments
 (0)