This repository was archived by the owner on Feb 10, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
lambdas/src/main/java/com/bobocode Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change 1+ package com .bobocode ;
2+
3+ import java .util .function .Consumer ;
4+ import java .util .function .Function ;
5+ import java .util .function .Predicate ;
6+ import java .util .function .Supplier ;
7+
8+ /**
9+ * An example of crazy lambda that is hard but still important to understand
10+ */
11+ public class CrazyLambdaExample {
12+ public static void main (String [] args ) {
13+ Supplier <Function <Predicate <String >, Consumer <String >>> stringPredicateToConsumerFunctionSupplier =
14+ getStringPredicateToConsumerFunctionSupplier ();
15+
16+ Function <Predicate <String >, Consumer <String >> stringPredicateConsumerFunction = stringPredicateToConsumerFunctionSupplier .get ();
17+ Consumer <String > stringIsEmptyChecker = stringPredicateConsumerFunction .apply (String ::isEmpty );
18+ stringIsEmptyChecker .accept ("" );
19+ }
20+
21+ /**
22+ * Returns the {@link Supplier} instance that supplies {@link Function} that receives a string {@link Predicate} as
23+ * a parameter and returns string {@link Consumer}
24+ *
25+ * @return an instance of supplier
26+ */
27+ private static Supplier <Function <Predicate <String >, Consumer <String >>> getStringPredicateToConsumerFunctionSupplier () {
28+ return () -> stringPredicate -> str -> System .out .println (stringPredicate .test (str ));
29+ }
30+
31+
32+ }
You can’t perform that action at this time.
0 commit comments