SlideShare a Scribd company logo
Beyond Lambdas, the aftermath
@DanielSawano
@DanielDeogun
About Us…
Daniel Deogun Daniel Sawano
Omegapoint
Stockholm - Gothenburg - Malmoe - Umea - New York
[insert code here]
Optionals 1
23 void _() {
24 final Advise advise = new Advise();
25
26 Optional.of(advise)
27 .map(Advise::cheap)
28 .orElse(advise.expensive());
29
30 }
Optionals 1
23 void _() {
24 final Advise advise = new Advise();
25
26 Optional.of(advise)
27 .map(Advise::cheap)
28 .orElseGet(advise::expensive);
29
30 }
Optionals 2
26 String _(final Optional<String> optOfSomeValue) {
27
28 return optOfSomeValue.map(v -> calculate(v))
29 .filter(someCriteria())
30 .map(v -> transform(v))
31 .orElseGet(() -> completelyDifferentCalculation());
32
33 }
Optionals 2
26 String _(final Optional<String> optOfSomeValue) {
27
28 if (optOfSomeValue.isPresent()) {
29 final String calculatedValue = calculate(optOfSomeValue.get());
30 if (someCriteria().test(calculatedValue)) {
31 return transform(calculatedValue);
32 }
33 }
34
35 return completelyDifferentCalculation();
36
37 }
Optionals 2
26 String _() {
27 return value()
28 .flatMap(v -> firstCalculation(v))
29 .orElseGet(() -> completelyDifferentCalculation());
30 }
31
32 Optional<String> value() {
33 return Optional.of(someValue());
34 }
35
36 Optional<String> firstCalculation(final String v) {
37 return Optional.of(calculate(v))
38 .filter(someCriteria())
39 .map(value -> transform(value));
40 }
Optionals 3
27 <T> void _(final Optional<T> argument) {
28 argument.map(a -> doSomething(a));
29 }
Optionals 3
25 <T> void _(final T argument) {
26 if (argument != null) {
27 doSomething(argument);
28 }
29 }
Optionals 3
26 <T> void _(final T argument) {
27 doSomething(notNull(argument));
28 }
Streams 1
30 @Test
31 public void _() {
32
33 final Stream<String> stream = elements().stream()
34 .sorted();
35
36 final String result = stream.collect(joining(","));
37
38 assertEquals("A,B,C", result);
39
40 }
41
42 static List<String> elements() {
43 return asList("C", "B", null, "A");
44 }
Streams 1
31 @Test
32 public void _() {
33
34 final Stream<String> stream = elements().stream()
35 .filter(Objects::nonNull)
36 .sorted();
37
38 final String result = stream.collect(joining(","));
39
40 assertEquals("A,B,C", result);
41
42 }
43
44 static List<String> elements() {
45 return asList("C", "B", null, "A");
46 }
Streams 2
27 @Test
28 public void _() {
29
30 final long idToFind = 6;
31 final Predicate<Item> idFilter = item -> item.id().equals(idToFind);
32
33 service().itemsMatching(idFilter)
34 .findFirst()
35 .ifPresent(Support::doSomething);
36
37 }
Streams 2
28 @Test
29 public void _() {
30
31 final long idToFind = 6;
32 final Predicate<Item> idFilter = item -> item.id().equals(idToFind);
33
34 service().itemsMatching(idFilter)
35 .reduce(toOneItem())
36 .ifPresent(Support::doSomething);
37
38 }
39
40 BinaryOperator<Item> toOneItem() {
41 return (item, item2) -> {
42 throw new IllegalStateException("Found more than one item with the same id");
43 };
44 }
Streams 3
29 private final UserService userService = new UserService();
30 private final OrderService orderService = new OrderService();
31
32 @Test
33 public void _() {
34 givenALoggedInUser(userService);
35
36 itemsToBuy().stream()
37 .map(item -> new Order(item.id(), currentUser().id()))
38 .forEach(orderService::sendOrder);
39
40 System.out.println(format("Sent %d orders", orderService.sentOrders()));
41 }
42
43 User currentUser() {
44 final User user = userService.currentUser();
45 validState(user != null, "No current user found");
46 return user;
47 }
Streams 3
29 private final UserService userService = new UserService();
30 private final OrderService orderService = new OrderService();
31
32 @Test
33 public void _() {
34 givenALoggedInUser(userService);
35
36 final User user = currentUser();
37 itemsToBuy().parallelStream()
38 .map(item -> new Order(item.id(), user.id()))
39 .forEach(orderService::sendOrder);
40
41 System.out.println(format("Sent %d orders", orderService.sentOrders()));
42 }
43
44 User currentUser() {
45 final User user = userService.currentUser();
46 validState(user != null, "No current user found");
47 return user;
48 }
LAmbdas 1
28 static Integer numberOfFreeApples(final User user,
29 final Function<User, Integer> foodRatio) {
30 return 2 * foodRatio.apply(user);
31 }
32
33 @Test
34 public void _() {
35
36 final Function<User, Integer> foodRatioForVisitors = u -> u.age() > 12 ? 2 : 1;
37
38 final int numberOfFreeApples = numberOfFreeApples(someUser(), foodRatioForVisitors);
39
40 System.out.println(format("Number of free apples: %d", numberOfFreeApples));
41
42 }
LAmbdas 1
29 @Test
30 public void _() {
31
32 final Function<User, Integer> foodRatioForVisitors = u -> u.age() > 12 ? 2 : 1;
33 final Function<User, Integer> age = User::age;
34
35 final int numberOfFreeApples_1 = numberOfFreeApples(someUser(), foodRatioForVisitors);
36 final int numberOfFreeApples_2 = numberOfFreeApples(someUser(), age); // This is a bug!
37
38 System.out.println(format("Number of free apples (1): %d", numberOfFreeApples_1));
39 System.out.println(format("Number of free apples (2): %d", numberOfFreeApples_2));
40
41 }
LAmbdas 1
28 @FunctionalInterface
29 interface FoodRatioStrategy {
30
31 Integer ratioFor(User user);
32 }
33
34 static Integer numberOfFreeApples(final User user,
35 final FoodRatioStrategy ratioStrategy) {
36 return 2 * ratioStrategy.ratioFor(user);
37 }
38
39 @Test
40 public void _() {
41
42 final FoodRatioStrategy foodRatioForVisitors = user -> user.age() > 12 ? 2 : 1;
43 final Function<User, Integer> age = User::age;
44
45 final Integer numberOfFreeApples_1 = numberOfFreeApples(someUser(), foodRatioForVisitors);
46 //final Integer numberOfFreeApples_2 = numberOfFreeApples(someUser(), age);
47
48 System.out.println(format("Number of free apples (1): %d", numberOfFreeApples_1));
49 }
LAmbdas 2
25 @Test
26 public void should_build_tesla() {
27
28 assertEquals(1000, new TeslaFactory().createTesla().engine().horsepower());
29
30 }
31
32 @Test
33 public void should_build_volvo() {
34
35 assertEquals(250, new VolvoFactory().createVolvo().engine().horsepower());
36
37 }
LAmbdas 3
29 @Test
30 public void _() {
31
32 final List<Integer> values = asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
33
34 allEvenNumbers(values);
35
36 System.out.println("Hello");
37
38 }
39
40 static List<Integer> allEvenNumbers(final List<Integer> values) {
41 return values.stream()
42 .filter(Support::isEven)
43 .collect(toList());
44 }
LAmbdas 3
31 @Test
32 public void _() {
33
34 final List<Integer> values = asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
35
36 final Supplier<List<Integer>> integers = () -> allEvenNumbers(values);
37
38 System.out.println(integers.get());
39
40 }
41
42 static List<Integer> allEvenNumbers(final List<Integer> values) {
43 return values.stream()
44 .filter(Support::isEven)
45 .collect(toList());
46 }
LAmbdas 4
24 private final String pattern;
25
26 public _14(final String pattern) {
27 this.pattern = pattern;
28 }
29
30 public List<String> allMatchingElements(final List<String> elements) {
31 return elements.stream()
32 .filter(e -> e.contains(pattern))
33 .collect(toList());
34 }
LAmbdas 4
25 private final String pattern;
26
27 public _14(final String pattern) {
28 this.pattern = pattern;
29 }
30
31 public List<String> allMatchingElements(final List<String> elements) {
32 return elements.stream()
33 .filter(matches(pattern))
34 .collect(toList());
35 }
36
37 private Predicate<String> matches(final String pattern) {
38 return e -> e.contains(pattern);
39 }
Q & A
[Questions]
Code examples can be found here:
https://github.com/sawano/jfokus-2016-beyond-lambdas
Thank you!
@DanielSawano @DanielDeogun

More Related Content

What's hot

Procedural Content Generation with Clojure
Procedural Content Generation with ClojureProcedural Content Generation with Clojure
Procedural Content Generation with ClojureMike Anderson
 
Idea for ineractive programming language
Idea for ineractive programming languageIdea for ineractive programming language
Idea for ineractive programming languageLincoln Hannah
 
Clojure for Data Science
Clojure for Data ScienceClojure for Data Science
Clojure for Data Sciencehenrygarner
 
The Ring programming language version 1.9 book - Part 46 of 210
The Ring programming language version 1.9 book - Part 46 of 210The Ring programming language version 1.9 book - Part 46 of 210
The Ring programming language version 1.9 book - Part 46 of 210Mahmoud Samir Fayed
 
Java Puzzle
Java PuzzleJava Puzzle
Java PuzzleSFilipp
 
Visual Studio.Net - Sql Server
Visual Studio.Net - Sql ServerVisual Studio.Net - Sql Server
Visual Studio.Net - Sql ServerDarwin Durand
 
Machine Learning Live
Machine Learning LiveMachine Learning Live
Machine Learning LiveMike Anderson
 
The Ring programming language version 1.5.4 book - Part 179 of 185
The Ring programming language version 1.5.4 book - Part 179 of 185The Ring programming language version 1.5.4 book - Part 179 of 185
The Ring programming language version 1.5.4 book - Part 179 of 185Mahmoud Samir Fayed
 
Distributed Machine Learning with Apache Mahout
Distributed Machine Learning with Apache MahoutDistributed Machine Learning with Apache Mahout
Distributed Machine Learning with Apache MahoutSuneel Marthi
 
Clojure for Data Science
Clojure for Data ScienceClojure for Data Science
Clojure for Data ScienceMike Anderson
 
The Ring programming language version 1.7 book - Part 91 of 196
The Ring programming language version 1.7 book - Part 91 of 196The Ring programming language version 1.7 book - Part 91 of 196
The Ring programming language version 1.7 book - Part 91 of 196Mahmoud Samir Fayed
 
Kristhyan kurtlazartezubia evidencia1-metodosnumericos
Kristhyan kurtlazartezubia evidencia1-metodosnumericosKristhyan kurtlazartezubia evidencia1-metodosnumericos
Kristhyan kurtlazartezubia evidencia1-metodosnumericosKristhyanAndreeKurtL
 
Matlab 1
Matlab 1Matlab 1
Matlab 1asguna
 

What's hot (19)

Procedural Content Generation with Clojure
Procedural Content Generation with ClojureProcedural Content Generation with Clojure
Procedural Content Generation with Clojure
 
Idea for ineractive programming language
Idea for ineractive programming languageIdea for ineractive programming language
Idea for ineractive programming language
 
Enter The Matrix
Enter The MatrixEnter The Matrix
Enter The Matrix
 
Clojure class
Clojure classClojure class
Clojure class
 
Xm lparsers
Xm lparsersXm lparsers
Xm lparsers
 
Clojure for Data Science
Clojure for Data ScienceClojure for Data Science
Clojure for Data Science
 
123
123123
123
 
Java file
Java fileJava file
Java file
 
The Ring programming language version 1.9 book - Part 46 of 210
The Ring programming language version 1.9 book - Part 46 of 210The Ring programming language version 1.9 book - Part 46 of 210
The Ring programming language version 1.9 book - Part 46 of 210
 
Java Puzzle
Java PuzzleJava Puzzle
Java Puzzle
 
Visual Studio.Net - Sql Server
Visual Studio.Net - Sql ServerVisual Studio.Net - Sql Server
Visual Studio.Net - Sql Server
 
Machine Learning Live
Machine Learning LiveMachine Learning Live
Machine Learning Live
 
The Ring programming language version 1.5.4 book - Part 179 of 185
The Ring programming language version 1.5.4 book - Part 179 of 185The Ring programming language version 1.5.4 book - Part 179 of 185
The Ring programming language version 1.5.4 book - Part 179 of 185
 
Distributed Machine Learning with Apache Mahout
Distributed Machine Learning with Apache MahoutDistributed Machine Learning with Apache Mahout
Distributed Machine Learning with Apache Mahout
 
Clojure for Data Science
Clojure for Data ScienceClojure for Data Science
Clojure for Data Science
 
The Ring programming language version 1.7 book - Part 91 of 196
The Ring programming language version 1.7 book - Part 91 of 196The Ring programming language version 1.7 book - Part 91 of 196
The Ring programming language version 1.7 book - Part 91 of 196
 
Kristhyan kurtlazartezubia evidencia1-metodosnumericos
Kristhyan kurtlazartezubia evidencia1-metodosnumericosKristhyan kurtlazartezubia evidencia1-metodosnumericos
Kristhyan kurtlazartezubia evidencia1-metodosnumericos
 
Java practical
Java practicalJava practical
Java practical
 
Matlab 1
Matlab 1Matlab 1
Matlab 1
 

Viewers also liked

Jfokus 2016 - A JVMs Journey into Polyglot Runtimes
Jfokus 2016 - A JVMs Journey into Polyglot RuntimesJfokus 2016 - A JVMs Journey into Polyglot Runtimes
Jfokus 2016 - A JVMs Journey into Polyglot RuntimesCharlie Gracie
 
2016 07-20-wp7-eclipse proposal
2016 07-20-wp7-eclipse proposal2016 07-20-wp7-eclipse proposal
2016 07-20-wp7-eclipse proposalAGILE IoT
 
ACCU16 "Let's Not Repeat the Mistakes of SOA: 'Micro' Services, Macro Organis...
ACCU16 "Let's Not Repeat the Mistakes of SOA: 'Micro' Services, Macro Organis...ACCU16 "Let's Not Repeat the Mistakes of SOA: 'Micro' Services, Macro Organis...
ACCU16 "Let's Not Repeat the Mistakes of SOA: 'Micro' Services, Macro Organis...Daniel Bryant
 
LMSUG 2015 "The Business Behind Microservices: Organisational, Architectural ...
LMSUG 2015 "The Business Behind Microservices: Organisational, Architectural ...LMSUG 2015 "The Business Behind Microservices: Organisational, Architectural ...
LMSUG 2015 "The Business Behind Microservices: Organisational, Architectural ...Daniel Bryant
 
OOP2016 "The Business Behind Microservices: Organisational, Architectural and...
OOP2016 "The Business Behind Microservices: Organisational, Architectural and...OOP2016 "The Business Behind Microservices: Organisational, Architectural and...
OOP2016 "The Business Behind Microservices: Organisational, Architectural and...Daniel Bryant
 
Thai tech startup ecosystem report 2017
Thai tech startup ecosystem report 2017Thai tech startup ecosystem report 2017
Thai tech startup ecosystem report 2017Techsauce Media
 

Viewers also liked (6)

Jfokus 2016 - A JVMs Journey into Polyglot Runtimes
Jfokus 2016 - A JVMs Journey into Polyglot RuntimesJfokus 2016 - A JVMs Journey into Polyglot Runtimes
Jfokus 2016 - A JVMs Journey into Polyglot Runtimes
 
2016 07-20-wp7-eclipse proposal
2016 07-20-wp7-eclipse proposal2016 07-20-wp7-eclipse proposal
2016 07-20-wp7-eclipse proposal
 
ACCU16 "Let's Not Repeat the Mistakes of SOA: 'Micro' Services, Macro Organis...
ACCU16 "Let's Not Repeat the Mistakes of SOA: 'Micro' Services, Macro Organis...ACCU16 "Let's Not Repeat the Mistakes of SOA: 'Micro' Services, Macro Organis...
ACCU16 "Let's Not Repeat the Mistakes of SOA: 'Micro' Services, Macro Organis...
 
LMSUG 2015 "The Business Behind Microservices: Organisational, Architectural ...
LMSUG 2015 "The Business Behind Microservices: Organisational, Architectural ...LMSUG 2015 "The Business Behind Microservices: Organisational, Architectural ...
LMSUG 2015 "The Business Behind Microservices: Organisational, Architectural ...
 
OOP2016 "The Business Behind Microservices: Organisational, Architectural and...
OOP2016 "The Business Behind Microservices: Organisational, Architectural and...OOP2016 "The Business Behind Microservices: Organisational, Architectural and...
OOP2016 "The Business Behind Microservices: Organisational, Architectural and...
 
Thai tech startup ecosystem report 2017
Thai tech startup ecosystem report 2017Thai tech startup ecosystem report 2017
Thai tech startup ecosystem report 2017
 

Similar to JFokus 2016 - Beyond Lambdas - the Aftermath

JDays 2016 - Beyond Lambdas - the Aftermath
JDays 2016 - Beyond Lambdas - the AftermathJDays 2016 - Beyond Lambdas - the Aftermath
JDays 2016 - Beyond Lambdas - the AftermathDaniel Sawano
 
Spotify 2016 - Beyond Lambdas - the Aftermath
Spotify 2016 - Beyond Lambdas - the AftermathSpotify 2016 - Beyond Lambdas - the Aftermath
Spotify 2016 - Beyond Lambdas - the AftermathDaniel Sawano
 
GeeCon 2016 - Beyond Lambdas, the Aftermath
GeeCon 2016 - Beyond Lambdas, the AftermathGeeCon 2016 - Beyond Lambdas, the Aftermath
GeeCon 2016 - Beyond Lambdas, the AftermathDaniel Sawano
 
ch12.DS_Store__MACOSXch12._.DS_Storech12section_1.D.docx
ch12.DS_Store__MACOSXch12._.DS_Storech12section_1.D.docxch12.DS_Store__MACOSXch12._.DS_Storech12section_1.D.docx
ch12.DS_Store__MACOSXch12._.DS_Storech12section_1.D.docxcravennichole326
 
Java 8 lambda expressions
Java 8 lambda expressionsJava 8 lambda expressions
Java 8 lambda expressionsLogan Chien
 
Lec 9 05_sept [compatibility mode]
Lec 9 05_sept [compatibility mode]Lec 9 05_sept [compatibility mode]
Lec 9 05_sept [compatibility mode]Palak Sanghani
 
Stratosphere Intro (Java and Scala Interface)
Stratosphere Intro (Java and Scala Interface)Stratosphere Intro (Java and Scala Interface)
Stratosphere Intro (Java and Scala Interface)Robert Metzger
 
Lec 8 03_sept [compatibility mode]
Lec 8 03_sept [compatibility mode]Lec 8 03_sept [compatibility mode]
Lec 8 03_sept [compatibility mode]Palak Sanghani
 
Extractors & Implicit conversions
Extractors & Implicit conversionsExtractors & Implicit conversions
Extractors & Implicit conversionsKnoldus Inc.
 
Flink Forward San Francisco 2018: Seth Wiesman - "Testing Stateful Streaming ...
Flink Forward San Francisco 2018: Seth Wiesman - "Testing Stateful Streaming ...Flink Forward San Francisco 2018: Seth Wiesman - "Testing Stateful Streaming ...
Flink Forward San Francisco 2018: Seth Wiesman - "Testing Stateful Streaming ...Flink Forward
 
20.1 Java working with abstraction
20.1 Java working with abstraction20.1 Java working with abstraction
20.1 Java working with abstractionIntro C# Book
 
Class & Object - User Defined Method
Class & Object - User Defined MethodClass & Object - User Defined Method
Class & Object - User Defined MethodPRN USM
 
Redux for ReactJS Programmers
Redux for ReactJS ProgrammersRedux for ReactJS Programmers
Redux for ReactJS ProgrammersDavid Rodenas
 
How to add an optimization for C# to RyuJIT
How to add an optimization for C# to RyuJITHow to add an optimization for C# to RyuJIT
How to add an optimization for C# to RyuJITEgor Bogatov
 

Similar to JFokus 2016 - Beyond Lambdas - the Aftermath (20)

JDays 2016 - Beyond Lambdas - the Aftermath
JDays 2016 - Beyond Lambdas - the AftermathJDays 2016 - Beyond Lambdas - the Aftermath
JDays 2016 - Beyond Lambdas - the Aftermath
 
Spotify 2016 - Beyond Lambdas - the Aftermath
Spotify 2016 - Beyond Lambdas - the AftermathSpotify 2016 - Beyond Lambdas - the Aftermath
Spotify 2016 - Beyond Lambdas - the Aftermath
 
GeeCon 2016 - Beyond Lambdas, the Aftermath
GeeCon 2016 - Beyond Lambdas, the AftermathGeeCon 2016 - Beyond Lambdas, the Aftermath
GeeCon 2016 - Beyond Lambdas, the Aftermath
 
ch12.DS_Store__MACOSXch12._.DS_Storech12section_1.D.docx
ch12.DS_Store__MACOSXch12._.DS_Storech12section_1.D.docxch12.DS_Store__MACOSXch12._.DS_Storech12section_1.D.docx
ch12.DS_Store__MACOSXch12._.DS_Storech12section_1.D.docx
 
Java 8 lambda expressions
Java 8 lambda expressionsJava 8 lambda expressions
Java 8 lambda expressions
 
Lec 9 05_sept [compatibility mode]
Lec 9 05_sept [compatibility mode]Lec 9 05_sept [compatibility mode]
Lec 9 05_sept [compatibility mode]
 
Graphical User Components Part 2
Graphical User Components Part 2Graphical User Components Part 2
Graphical User Components Part 2
 
Stratosphere Intro (Java and Scala Interface)
Stratosphere Intro (Java and Scala Interface)Stratosphere Intro (Java and Scala Interface)
Stratosphere Intro (Java and Scala Interface)
 
Functional Programming
Functional ProgrammingFunctional Programming
Functional Programming
 
Lec 8 03_sept [compatibility mode]
Lec 8 03_sept [compatibility mode]Lec 8 03_sept [compatibility mode]
Lec 8 03_sept [compatibility mode]
 
Extractors & Implicit conversions
Extractors & Implicit conversionsExtractors & Implicit conversions
Extractors & Implicit conversions
 
Flink Forward San Francisco 2018: Seth Wiesman - "Testing Stateful Streaming ...
Flink Forward San Francisco 2018: Seth Wiesman - "Testing Stateful Streaming ...Flink Forward San Francisco 2018: Seth Wiesman - "Testing Stateful Streaming ...
Flink Forward San Francisco 2018: Seth Wiesman - "Testing Stateful Streaming ...
 
20.1 Java working with abstraction
20.1 Java working with abstraction20.1 Java working with abstraction
20.1 Java working with abstraction
 
PRACTICAL COMPUTING
PRACTICAL COMPUTINGPRACTICAL COMPUTING
PRACTICAL COMPUTING
 
Class & Object - User Defined Method
Class & Object - User Defined MethodClass & Object - User Defined Method
Class & Object - User Defined Method
 
Redux for ReactJS Programmers
Redux for ReactJS ProgrammersRedux for ReactJS Programmers
Redux for ReactJS Programmers
 
How to add an optimization for C# to RyuJIT
How to add an optimization for C# to RyuJITHow to add an optimization for C# to RyuJIT
How to add an optimization for C# to RyuJIT
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 

More from Daniel Sawano

GeeCon Prague 2017 - Cracking the Code to Secure Software
GeeCon Prague 2017 - Cracking the Code to Secure SoftwareGeeCon Prague 2017 - Cracking the Code to Secure Software
GeeCon Prague 2017 - Cracking the Code to Secure SoftwareDaniel Sawano
 
Devoxx PL 2017 - Cracking the Code to Secure Software
Devoxx PL 2017 - Cracking the Code to Secure SoftwareDevoxx PL 2017 - Cracking the Code to Secure Software
Devoxx PL 2017 - Cracking the Code to Secure SoftwareDaniel Sawano
 
DevDays LT 2017 - Secure by Design
DevDays LT 2017 - Secure by DesignDevDays LT 2017 - Secure by Design
DevDays LT 2017 - Secure by DesignDaniel Sawano
 
Devoxx PL 2016 - Beyond Lambdas, the Aftermath
Devoxx PL 2016 - Beyond Lambdas, the AftermathDevoxx PL 2016 - Beyond Lambdas, the Aftermath
Devoxx PL 2016 - Beyond Lambdas, the AftermathDaniel Sawano
 
Devoxx, MA, 2015, Failing Continuous Delivery
Devoxx, MA, 2015, Failing Continuous DeliveryDevoxx, MA, 2015, Failing Continuous Delivery
Devoxx, MA, 2015, Failing Continuous DeliveryDaniel Sawano
 
Failing Continuous Delivery, Agile Prague 2015
Failing Continuous Delivery, Agile Prague 2015Failing Continuous Delivery, Agile Prague 2015
Failing Continuous Delivery, Agile Prague 2015Daniel Sawano
 
Failing Continuous Delivery, Devoxx Poland, 2015
Failing Continuous Delivery, Devoxx Poland, 2015Failing Continuous Delivery, Devoxx Poland, 2015
Failing Continuous Delivery, Devoxx Poland, 2015Daniel Sawano
 
Things Every Professional Programmer Should Know
Things Every Professional Programmer Should KnowThings Every Professional Programmer Should Know
Things Every Professional Programmer Should KnowDaniel Sawano
 
Failing Continuous Delivery, JDays, 2015
Failing Continuous Delivery, JDays, 2015Failing Continuous Delivery, JDays, 2015
Failing Continuous Delivery, JDays, 2015Daniel Sawano
 
Reactive Programming With Akka - Lessons Learned
Reactive Programming With Akka - Lessons LearnedReactive Programming With Akka - Lessons Learned
Reactive Programming With Akka - Lessons LearnedDaniel Sawano
 

More from Daniel Sawano (11)

GeeCon Prague 2017 - Cracking the Code to Secure Software
GeeCon Prague 2017 - Cracking the Code to Secure SoftwareGeeCon Prague 2017 - Cracking the Code to Secure Software
GeeCon Prague 2017 - Cracking the Code to Secure Software
 
Devoxx PL 2017 - Cracking the Code to Secure Software
Devoxx PL 2017 - Cracking the Code to Secure SoftwareDevoxx PL 2017 - Cracking the Code to Secure Software
Devoxx PL 2017 - Cracking the Code to Secure Software
 
DevDays LT 2017 - Secure by Design
DevDays LT 2017 - Secure by DesignDevDays LT 2017 - Secure by Design
DevDays LT 2017 - Secure by Design
 
Devoxx PL 2016 - Beyond Lambdas, the Aftermath
Devoxx PL 2016 - Beyond Lambdas, the AftermathDevoxx PL 2016 - Beyond Lambdas, the Aftermath
Devoxx PL 2016 - Beyond Lambdas, the Aftermath
 
Devoxx, MA, 2015, Failing Continuous Delivery
Devoxx, MA, 2015, Failing Continuous DeliveryDevoxx, MA, 2015, Failing Continuous Delivery
Devoxx, MA, 2015, Failing Continuous Delivery
 
Failing Continuous Delivery, Agile Prague 2015
Failing Continuous Delivery, Agile Prague 2015Failing Continuous Delivery, Agile Prague 2015
Failing Continuous Delivery, Agile Prague 2015
 
Failing Continuous Delivery, Devoxx Poland, 2015
Failing Continuous Delivery, Devoxx Poland, 2015Failing Continuous Delivery, Devoxx Poland, 2015
Failing Continuous Delivery, Devoxx Poland, 2015
 
Things Every Professional Programmer Should Know
Things Every Professional Programmer Should KnowThings Every Professional Programmer Should Know
Things Every Professional Programmer Should Know
 
Failing Continuous Delivery, JDays, 2015
Failing Continuous Delivery, JDays, 2015Failing Continuous Delivery, JDays, 2015
Failing Continuous Delivery, JDays, 2015
 
Akka Made Our Day
Akka Made Our DayAkka Made Our Day
Akka Made Our Day
 
Reactive Programming With Akka - Lessons Learned
Reactive Programming With Akka - Lessons LearnedReactive Programming With Akka - Lessons Learned
Reactive Programming With Akka - Lessons Learned
 

Recently uploaded

Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdfMastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdfmbmh111980
 
Breaking the Code : A Guide to WhatsApp Business API.pdf
Breaking the Code : A Guide to WhatsApp Business API.pdfBreaking the Code : A Guide to WhatsApp Business API.pdf
Breaking the Code : A Guide to WhatsApp Business API.pdfMeon Technology
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILNatan Silnitsky
 
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAGAI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAGAlluxio, Inc.
 
De mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FMEDe mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FMEJelle | Nordend
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandIES VE
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessWSO2
 
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...Abortion Clinic
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownloadvrstrong314
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfOrtus Solutions, Corp
 
AI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning FrameworkAI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning FrameworkAlluxio, Inc.
 
Crafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM IntegrationCrafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM IntegrationWave PLM
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyanic lab
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamtakuyayamamoto1800
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns
 
AI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in MichelangeloAI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in MichelangeloAlluxio, Inc.
 
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?XfilesPro
 
Advanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should KnowAdvanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should KnowPeter Caitens
 

Recently uploaded (20)

Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdfMastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
 
Breaking the Code : A Guide to WhatsApp Business API.pdf
Breaking the Code : A Guide to WhatsApp Business API.pdfBreaking the Code : A Guide to WhatsApp Business API.pdf
Breaking the Code : A Guide to WhatsApp Business API.pdf
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAGAI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
De mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FMEDe mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FME
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
 
AI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning FrameworkAI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning Framework
 
Crafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM IntegrationCrafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM Integration
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
AI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in MichelangeloAI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in Michelangelo
 
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
 
Advanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should KnowAdvanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should Know
 

JFokus 2016 - Beyond Lambdas - the Aftermath

  • 1. Beyond Lambdas, the aftermath @DanielSawano @DanielDeogun
  • 2. About Us… Daniel Deogun Daniel Sawano Omegapoint Stockholm - Gothenburg - Malmoe - Umea - New York
  • 4. Optionals 1 23 void _() { 24 final Advise advise = new Advise(); 25 26 Optional.of(advise) 27 .map(Advise::cheap) 28 .orElse(advise.expensive()); 29 30 }
  • 5. Optionals 1 23 void _() { 24 final Advise advise = new Advise(); 25 26 Optional.of(advise) 27 .map(Advise::cheap) 28 .orElseGet(advise::expensive); 29 30 }
  • 6. Optionals 2 26 String _(final Optional<String> optOfSomeValue) { 27 28 return optOfSomeValue.map(v -> calculate(v)) 29 .filter(someCriteria()) 30 .map(v -> transform(v)) 31 .orElseGet(() -> completelyDifferentCalculation()); 32 33 }
  • 7. Optionals 2 26 String _(final Optional<String> optOfSomeValue) { 27 28 if (optOfSomeValue.isPresent()) { 29 final String calculatedValue = calculate(optOfSomeValue.get()); 30 if (someCriteria().test(calculatedValue)) { 31 return transform(calculatedValue); 32 } 33 } 34 35 return completelyDifferentCalculation(); 36 37 }
  • 8. Optionals 2 26 String _() { 27 return value() 28 .flatMap(v -> firstCalculation(v)) 29 .orElseGet(() -> completelyDifferentCalculation()); 30 } 31 32 Optional<String> value() { 33 return Optional.of(someValue()); 34 } 35 36 Optional<String> firstCalculation(final String v) { 37 return Optional.of(calculate(v)) 38 .filter(someCriteria()) 39 .map(value -> transform(value)); 40 }
  • 9. Optionals 3 27 <T> void _(final Optional<T> argument) { 28 argument.map(a -> doSomething(a)); 29 }
  • 10. Optionals 3 25 <T> void _(final T argument) { 26 if (argument != null) { 27 doSomething(argument); 28 } 29 }
  • 11. Optionals 3 26 <T> void _(final T argument) { 27 doSomething(notNull(argument)); 28 }
  • 12. Streams 1 30 @Test 31 public void _() { 32 33 final Stream<String> stream = elements().stream() 34 .sorted(); 35 36 final String result = stream.collect(joining(",")); 37 38 assertEquals("A,B,C", result); 39 40 } 41 42 static List<String> elements() { 43 return asList("C", "B", null, "A"); 44 }
  • 13. Streams 1 31 @Test 32 public void _() { 33 34 final Stream<String> stream = elements().stream() 35 .filter(Objects::nonNull) 36 .sorted(); 37 38 final String result = stream.collect(joining(",")); 39 40 assertEquals("A,B,C", result); 41 42 } 43 44 static List<String> elements() { 45 return asList("C", "B", null, "A"); 46 }
  • 14. Streams 2 27 @Test 28 public void _() { 29 30 final long idToFind = 6; 31 final Predicate<Item> idFilter = item -> item.id().equals(idToFind); 32 33 service().itemsMatching(idFilter) 34 .findFirst() 35 .ifPresent(Support::doSomething); 36 37 }
  • 15. Streams 2 28 @Test 29 public void _() { 30 31 final long idToFind = 6; 32 final Predicate<Item> idFilter = item -> item.id().equals(idToFind); 33 34 service().itemsMatching(idFilter) 35 .reduce(toOneItem()) 36 .ifPresent(Support::doSomething); 37 38 } 39 40 BinaryOperator<Item> toOneItem() { 41 return (item, item2) -> { 42 throw new IllegalStateException("Found more than one item with the same id"); 43 }; 44 }
  • 16. Streams 3 29 private final UserService userService = new UserService(); 30 private final OrderService orderService = new OrderService(); 31 32 @Test 33 public void _() { 34 givenALoggedInUser(userService); 35 36 itemsToBuy().stream() 37 .map(item -> new Order(item.id(), currentUser().id())) 38 .forEach(orderService::sendOrder); 39 40 System.out.println(format("Sent %d orders", orderService.sentOrders())); 41 } 42 43 User currentUser() { 44 final User user = userService.currentUser(); 45 validState(user != null, "No current user found"); 46 return user; 47 }
  • 17. Streams 3 29 private final UserService userService = new UserService(); 30 private final OrderService orderService = new OrderService(); 31 32 @Test 33 public void _() { 34 givenALoggedInUser(userService); 35 36 final User user = currentUser(); 37 itemsToBuy().parallelStream() 38 .map(item -> new Order(item.id(), user.id())) 39 .forEach(orderService::sendOrder); 40 41 System.out.println(format("Sent %d orders", orderService.sentOrders())); 42 } 43 44 User currentUser() { 45 final User user = userService.currentUser(); 46 validState(user != null, "No current user found"); 47 return user; 48 }
  • 18. LAmbdas 1 28 static Integer numberOfFreeApples(final User user, 29 final Function<User, Integer> foodRatio) { 30 return 2 * foodRatio.apply(user); 31 } 32 33 @Test 34 public void _() { 35 36 final Function<User, Integer> foodRatioForVisitors = u -> u.age() > 12 ? 2 : 1; 37 38 final int numberOfFreeApples = numberOfFreeApples(someUser(), foodRatioForVisitors); 39 40 System.out.println(format("Number of free apples: %d", numberOfFreeApples)); 41 42 }
  • 19. LAmbdas 1 29 @Test 30 public void _() { 31 32 final Function<User, Integer> foodRatioForVisitors = u -> u.age() > 12 ? 2 : 1; 33 final Function<User, Integer> age = User::age; 34 35 final int numberOfFreeApples_1 = numberOfFreeApples(someUser(), foodRatioForVisitors); 36 final int numberOfFreeApples_2 = numberOfFreeApples(someUser(), age); // This is a bug! 37 38 System.out.println(format("Number of free apples (1): %d", numberOfFreeApples_1)); 39 System.out.println(format("Number of free apples (2): %d", numberOfFreeApples_2)); 40 41 }
  • 20. LAmbdas 1 28 @FunctionalInterface 29 interface FoodRatioStrategy { 30 31 Integer ratioFor(User user); 32 } 33 34 static Integer numberOfFreeApples(final User user, 35 final FoodRatioStrategy ratioStrategy) { 36 return 2 * ratioStrategy.ratioFor(user); 37 } 38 39 @Test 40 public void _() { 41 42 final FoodRatioStrategy foodRatioForVisitors = user -> user.age() > 12 ? 2 : 1; 43 final Function<User, Integer> age = User::age; 44 45 final Integer numberOfFreeApples_1 = numberOfFreeApples(someUser(), foodRatioForVisitors); 46 //final Integer numberOfFreeApples_2 = numberOfFreeApples(someUser(), age); 47 48 System.out.println(format("Number of free apples (1): %d", numberOfFreeApples_1)); 49 }
  • 21. LAmbdas 2 25 @Test 26 public void should_build_tesla() { 27 28 assertEquals(1000, new TeslaFactory().createTesla().engine().horsepower()); 29 30 } 31 32 @Test 33 public void should_build_volvo() { 34 35 assertEquals(250, new VolvoFactory().createVolvo().engine().horsepower()); 36 37 }
  • 22. LAmbdas 3 29 @Test 30 public void _() { 31 32 final List<Integer> values = asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); 33 34 allEvenNumbers(values); 35 36 System.out.println("Hello"); 37 38 } 39 40 static List<Integer> allEvenNumbers(final List<Integer> values) { 41 return values.stream() 42 .filter(Support::isEven) 43 .collect(toList()); 44 }
  • 23. LAmbdas 3 31 @Test 32 public void _() { 33 34 final List<Integer> values = asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); 35 36 final Supplier<List<Integer>> integers = () -> allEvenNumbers(values); 37 38 System.out.println(integers.get()); 39 40 } 41 42 static List<Integer> allEvenNumbers(final List<Integer> values) { 43 return values.stream() 44 .filter(Support::isEven) 45 .collect(toList()); 46 }
  • 24. LAmbdas 4 24 private final String pattern; 25 26 public _14(final String pattern) { 27 this.pattern = pattern; 28 } 29 30 public List<String> allMatchingElements(final List<String> elements) { 31 return elements.stream() 32 .filter(e -> e.contains(pattern)) 33 .collect(toList()); 34 }
  • 25. LAmbdas 4 25 private final String pattern; 26 27 public _14(final String pattern) { 28 this.pattern = pattern; 29 } 30 31 public List<String> allMatchingElements(final List<String> elements) { 32 return elements.stream() 33 .filter(matches(pattern)) 34 .collect(toList()); 35 } 36 37 private Predicate<String> matches(final String pattern) { 38 return e -> e.contains(pattern); 39 }
  • 27. Code examples can be found here: https://github.com/sawano/jfokus-2016-beyond-lambdas