mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-14 22:58:36 +00:00
docs: update function composition pattern
This commit is contained in:
@@ -25,9 +25,10 @@
|
||||
package com.iluwatar.function.composition;
|
||||
|
||||
import java.util.function.Function;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/** Main application class to demonstrate the use of function composition. */
|
||||
@Slf4j
|
||||
public class App {
|
||||
|
||||
/**
|
||||
@@ -36,7 +37,6 @@ public class App {
|
||||
* @param args command line arguments (not used)
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
final var logger = LoggerFactory.getLogger(App.class);
|
||||
Function<Integer, Integer> timesTwo = x -> x * 2;
|
||||
Function<Integer, Integer> square = x -> x * x;
|
||||
|
||||
@@ -44,6 +44,6 @@ public class App {
|
||||
FunctionComposer.composeFunctions(timesTwo, square);
|
||||
|
||||
int result = composedFunction.apply(3);
|
||||
logger.info("Result of composing 'timesTwo' and 'square' functions applied to 3 is: " + result);
|
||||
LOGGER.info("Result of composing 'timesTwo' and 'square' functions applied to 3 is: " + result);
|
||||
}
|
||||
}
|
||||
|
||||
+2
@@ -32,6 +32,8 @@ import java.util.function.Function;
|
||||
*/
|
||||
public class FunctionComposer {
|
||||
|
||||
private FunctionComposer() {}
|
||||
|
||||
/**
|
||||
* Composes two functions where the output of the first function becomes the input of the second
|
||||
* function.
|
||||
|
||||
+1
-1
@@ -30,7 +30,7 @@ import java.util.function.Function;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/** Test class for FunctionComposer. */
|
||||
public class FunctionComposerTest {
|
||||
class FunctionComposerTest {
|
||||
|
||||
/** Tests the composition of two functions. */
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user