SlideShare a Scribd company logo
1 of 29
Download to read offline
Beyond Lambdas, the
aftermath
@DanielSawano
@DanielDeogun
Deogun - Sawano, 11-13 May 2016
About us…
Daniel Sawano, Daniel Deogun Kraków, 11-13 May 2016
Daniel Deogun Daniel Sawano
Stockholm - Gothenburg - Malmoe - Umea - New York
[inert code here]
Daniel Sawano, Daniel Deogun Kraków, 11-13 May 2016
Optionals 1
7 final Oracle oracle = new Oracle();
8
9 String _() {
10 final Advise advise = currentAdvise();
11
12 if (advise != null) {
13 return advise.cheap();
14 }
15 else {
16 return oracle.advise().expensive();
17 }
18 }
Optionals 1
25 final Oracle oracle = new Oracle();
26
27 String _() {
28 final Advise advise = currentAdvise();
29
30 return Optional.ofNullable(advise)
31 .map(Advise::cheap)
32 .orElse(oracle.advise().expensive());
33 }
Optionals 1
25 final Oracle oracle = new Oracle();
26
27 String _() {
28 final Advise advise = currentAdvise();
29
30 return Optional.ofNullable(advise)
31 .map(Advise::cheap)
32 .orElseGet( () -> oracle.advise().expensive());
33 }
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
Daniel Sawano, Daniel Deogun Kraków, 11-13 May 2016
[Questions]
Code examples can be found here:
https://github.com/sawano/beyond-lambdas-the-aftermath
Daniel Sawano, Daniel Deogun Kraków, 11-13 May 2016
Thank you!
@DanielSawano @DanielDeogun
Daniel Sawano, Daniel Deogun Kraków, 11-13 May 2016

More Related Content

What's hot

Important java programs(collection+file)
Important java programs(collection+file)Important java programs(collection+file)
Important java programs(collection+file)Alok Kumar
 
Pattern printing programs
Pattern printing programsPattern printing programs
Pattern printing programsMukesh Tekwani
 
TI1220 Lecture 6: First-class Functions
TI1220 Lecture 6: First-class FunctionsTI1220 Lecture 6: First-class Functions
TI1220 Lecture 6: First-class FunctionsEelco Visser
 
C# console programms
C# console programmsC# console programms
C# console programmsYasir Khan
 
JAVA 8 : Migration et enjeux stratégiques en entreprise
JAVA 8 : Migration et enjeux stratégiques en entrepriseJAVA 8 : Migration et enjeux stratégiques en entreprise
JAVA 8 : Migration et enjeux stratégiques en entrepriseSOAT
 
The Ring programming language version 1.5.3 book - Part 10 of 184
The Ring programming language version 1.5.3 book - Part 10 of 184The Ring programming language version 1.5.3 book - Part 10 of 184
The Ring programming language version 1.5.3 book - Part 10 of 184Mahmoud Samir Fayed
 
The Ring programming language version 1.5.4 book - Part 10 of 185
The Ring programming language version 1.5.4 book - Part 10 of 185The Ring programming language version 1.5.4 book - Part 10 of 185
The Ring programming language version 1.5.4 book - Part 10 of 185Mahmoud Samir Fayed
 
The Ring programming language version 1.2 book - Part 23 of 84
The Ring programming language version 1.2 book - Part 23 of 84The Ring programming language version 1.2 book - Part 23 of 84
The Ring programming language version 1.2 book - Part 23 of 84Mahmoud Samir Fayed
 
The Ring programming language version 1.2 book - Part 24 of 84
The Ring programming language version 1.2 book - Part 24 of 84The Ring programming language version 1.2 book - Part 24 of 84
The Ring programming language version 1.2 book - Part 24 of 84Mahmoud Samir Fayed
 
Java Performance Puzzlers
Java Performance PuzzlersJava Performance Puzzlers
Java Performance PuzzlersDoug Hawkins
 
Java_practical_handbook
Java_practical_handbookJava_practical_handbook
Java_practical_handbookManusha Dilan
 
RMI Java Programming Lab Manual 2019
RMI Java Programming Lab Manual 2019RMI Java Programming Lab Manual 2019
RMI Java Programming Lab Manual 2019Gebreigziabher Ab
 
Java PRACTICAL file
Java PRACTICAL fileJava PRACTICAL file
Java PRACTICAL fileRACHIT_GUPTA
 
The Ring programming language version 1.3 book - Part 24 of 88
The Ring programming language version 1.3 book - Part 24 of 88The Ring programming language version 1.3 book - Part 24 of 88
The Ring programming language version 1.3 book - Part 24 of 88Mahmoud Samir Fayed
 

What's hot (19)

Important java programs(collection+file)
Important java programs(collection+file)Important java programs(collection+file)
Important java programs(collection+file)
 
C# labprograms
C# labprogramsC# labprograms
C# labprograms
 
Pattern printing programs
Pattern printing programsPattern printing programs
Pattern printing programs
 
Oop lecture9 13
Oop lecture9 13Oop lecture9 13
Oop lecture9 13
 
Java programs
Java programsJava programs
Java programs
 
TI1220 Lecture 6: First-class Functions
TI1220 Lecture 6: First-class FunctionsTI1220 Lecture 6: First-class Functions
TI1220 Lecture 6: First-class Functions
 
C# console programms
C# console programmsC# console programms
C# console programms
 
JAVA 8 : Migration et enjeux stratégiques en entreprise
JAVA 8 : Migration et enjeux stratégiques en entrepriseJAVA 8 : Migration et enjeux stratégiques en entreprise
JAVA 8 : Migration et enjeux stratégiques en entreprise
 
The Ring programming language version 1.5.3 book - Part 10 of 184
The Ring programming language version 1.5.3 book - Part 10 of 184The Ring programming language version 1.5.3 book - Part 10 of 184
The Ring programming language version 1.5.3 book - Part 10 of 184
 
.net progrmming part2
.net progrmming part2.net progrmming part2
.net progrmming part2
 
The Ring programming language version 1.5.4 book - Part 10 of 185
The Ring programming language version 1.5.4 book - Part 10 of 185The Ring programming language version 1.5.4 book - Part 10 of 185
The Ring programming language version 1.5.4 book - Part 10 of 185
 
The Ring programming language version 1.2 book - Part 23 of 84
The Ring programming language version 1.2 book - Part 23 of 84The Ring programming language version 1.2 book - Part 23 of 84
The Ring programming language version 1.2 book - Part 23 of 84
 
The Ring programming language version 1.2 book - Part 24 of 84
The Ring programming language version 1.2 book - Part 24 of 84The Ring programming language version 1.2 book - Part 24 of 84
The Ring programming language version 1.2 book - Part 24 of 84
 
Java Performance Puzzlers
Java Performance PuzzlersJava Performance Puzzlers
Java Performance Puzzlers
 
Java_practical_handbook
Java_practical_handbookJava_practical_handbook
Java_practical_handbook
 
RMI Java Programming Lab Manual 2019
RMI Java Programming Lab Manual 2019RMI Java Programming Lab Manual 2019
RMI Java Programming Lab Manual 2019
 
Java PRACTICAL file
Java PRACTICAL fileJava PRACTICAL file
Java PRACTICAL file
 
Dsprograms(2nd cse)
Dsprograms(2nd cse)Dsprograms(2nd cse)
Dsprograms(2nd cse)
 
The Ring programming language version 1.3 book - Part 24 of 88
The Ring programming language version 1.3 book - Part 24 of 88The Ring programming language version 1.3 book - Part 24 of 88
The Ring programming language version 1.3 book - Part 24 of 88
 

Viewers also liked

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
 
Chuck Brooks; Cybersecurity & Homeland Security Leadership Profile
Chuck Brooks; Cybersecurity & Homeland Security Leadership ProfileChuck Brooks; Cybersecurity & Homeland Security Leadership Profile
Chuck Brooks; Cybersecurity & Homeland Security Leadership ProfileChuck Brooks
 
Becoming current spring_14
Becoming current spring_14Becoming current spring_14
Becoming current spring_14countrygirl3
 
Proyeksi vektor aji santoso ( 31 ) msp
Proyeksi vektor aji santoso ( 31 ) mspProyeksi vektor aji santoso ( 31 ) msp
Proyeksi vektor aji santoso ( 31 ) msplaurisahat07
 
Financial Management & Corporate Advisory For Your Business
Financial Management & Corporate Advisory For Your BusinessFinancial Management & Corporate Advisory For Your Business
Financial Management & Corporate Advisory For Your BusinessSorin Popescu
 
Mobile Marketing for Health Clubs Webinar - June 2016
Mobile Marketing for Health Clubs Webinar - June 2016Mobile Marketing for Health Clubs Webinar - June 2016
Mobile Marketing for Health Clubs Webinar - June 2016Netpulse
 
Customer service careers
Customer service careersCustomer service careers
Customer service careerscrew
 
WordCamp Sydney 2016 - Day 2 Closing Remarks
WordCamp Sydney 2016 - Day 2 Closing RemarksWordCamp Sydney 2016 - Day 2 Closing Remarks
WordCamp Sydney 2016 - Day 2 Closing RemarksWordCamp Sydney
 
Pourquoi les evenements sont importants
Pourquoi les evenements sont importantsPourquoi les evenements sont importants
Pourquoi les evenements sont importantsEmilien Pecoul
 
That's So Fake: Exploring Critical Literacy
That's So Fake: Exploring Critical LiteracyThat's So Fake: Exploring Critical Literacy
That's So Fake: Exploring Critical LiteracyDean Shareski
 
How to develop a mobile app for events and conferences with little to no reso...
How to develop a mobile app for events and conferences with little to no reso...How to develop a mobile app for events and conferences with little to no reso...
How to develop a mobile app for events and conferences with little to no reso...Matthew Shoup
 
Люцко Н.М. Организационно-педагогические и правовые основы формирования незав...
Люцко Н.М. Организационно-педагогические и правовые основы формирования незав...Люцко Н.М. Организационно-педагогические и правовые основы формирования незав...
Люцко Н.М. Организационно-педагогические и правовые основы формирования незав...Natallia Liutsko
 
Zinnov Confluence 2014: Edge of Tomorrow: Fundamental Shifts Shaping Our Future
Zinnov Confluence 2014: Edge of Tomorrow: Fundamental Shifts Shaping Our Future Zinnov Confluence 2014: Edge of Tomorrow: Fundamental Shifts Shaping Our Future
Zinnov Confluence 2014: Edge of Tomorrow: Fundamental Shifts Shaping Our Future Aricent
 
Personal and Personalized Learning
Personal and Personalized LearningPersonal and Personalized Learning
Personal and Personalized LearningDean Shareski
 
Yahoo! research - 'Appetite' - the hunger for mobile media
Yahoo! research - 'Appetite' - the hunger for mobile mediaYahoo! research - 'Appetite' - the hunger for mobile media
Yahoo! research - 'Appetite' - the hunger for mobile mediaPatrick Hourihan
 
Curriculum vitae sv
Curriculum vitae svCurriculum vitae sv
Curriculum vitae svBo Ericsson
 

Viewers also liked (20)

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
 
Evolucion De La Ocmunicaion
Evolucion De La OcmunicaionEvolucion De La Ocmunicaion
Evolucion De La Ocmunicaion
 
Chuck Brooks; Cybersecurity & Homeland Security Leadership Profile
Chuck Brooks; Cybersecurity & Homeland Security Leadership ProfileChuck Brooks; Cybersecurity & Homeland Security Leadership Profile
Chuck Brooks; Cybersecurity & Homeland Security Leadership Profile
 
Becoming current spring_14
Becoming current spring_14Becoming current spring_14
Becoming current spring_14
 
Proyeksi vektor aji santoso ( 31 ) msp
Proyeksi vektor aji santoso ( 31 ) mspProyeksi vektor aji santoso ( 31 ) msp
Proyeksi vektor aji santoso ( 31 ) msp
 
Financial Management & Corporate Advisory For Your Business
Financial Management & Corporate Advisory For Your BusinessFinancial Management & Corporate Advisory For Your Business
Financial Management & Corporate Advisory For Your Business
 
Mobile Marketing for Health Clubs Webinar - June 2016
Mobile Marketing for Health Clubs Webinar - June 2016Mobile Marketing for Health Clubs Webinar - June 2016
Mobile Marketing for Health Clubs Webinar - June 2016
 
Customer service careers
Customer service careersCustomer service careers
Customer service careers
 
WordCamp Sydney 2016 - Day 2 Closing Remarks
WordCamp Sydney 2016 - Day 2 Closing RemarksWordCamp Sydney 2016 - Day 2 Closing Remarks
WordCamp Sydney 2016 - Day 2 Closing Remarks
 
Pourquoi les evenements sont importants
Pourquoi les evenements sont importantsPourquoi les evenements sont importants
Pourquoi les evenements sont importants
 
That's So Fake: Exploring Critical Literacy
That's So Fake: Exploring Critical LiteracyThat's So Fake: Exploring Critical Literacy
That's So Fake: Exploring Critical Literacy
 
How to develop a mobile app for events and conferences with little to no reso...
How to develop a mobile app for events and conferences with little to no reso...How to develop a mobile app for events and conferences with little to no reso...
How to develop a mobile app for events and conferences with little to no reso...
 
Люцко Н.М. Организационно-педагогические и правовые основы формирования незав...
Люцко Н.М. Организационно-педагогические и правовые основы формирования незав...Люцко Н.М. Организационно-педагогические и правовые основы формирования незав...
Люцко Н.М. Организационно-педагогические и правовые основы формирования незав...
 
Zinnov Confluence 2014: Edge of Tomorrow: Fundamental Shifts Shaping Our Future
Zinnov Confluence 2014: Edge of Tomorrow: Fundamental Shifts Shaping Our Future Zinnov Confluence 2014: Edge of Tomorrow: Fundamental Shifts Shaping Our Future
Zinnov Confluence 2014: Edge of Tomorrow: Fundamental Shifts Shaping Our Future
 
TENDANCES BRAND CONTENT 2015 : Just Dance présenté par Alban Dechelotte de Co...
TENDANCES BRAND CONTENT 2015 : Just Dance présenté par Alban Dechelotte de Co...TENDANCES BRAND CONTENT 2015 : Just Dance présenté par Alban Dechelotte de Co...
TENDANCES BRAND CONTENT 2015 : Just Dance présenté par Alban Dechelotte de Co...
 
Personal and Personalized Learning
Personal and Personalized LearningPersonal and Personalized Learning
Personal and Personalized Learning
 
Junho jardim
Junho jardimJunho jardim
Junho jardim
 
Yahoo! research - 'Appetite' - the hunger for mobile media
Yahoo! research - 'Appetite' - the hunger for mobile mediaYahoo! research - 'Appetite' - the hunger for mobile media
Yahoo! research - 'Appetite' - the hunger for mobile media
 
Hotspot
HotspotHotspot
Hotspot
 
Curriculum vitae sv
Curriculum vitae svCurriculum vitae sv
Curriculum vitae sv
 

Similar to GeeCon 2016 - Beyond Lambdas, the Aftermath

JFokus 2016 - Beyond Lambdas - the Aftermath
JFokus 2016 - Beyond Lambdas - the AftermathJFokus 2016 - Beyond Lambdas - the Aftermath
JFokus 2016 - Beyond Lambdas - the AftermathDaniel Sawano
 
The Ring programming language version 1.6 book - Part 37 of 189
The Ring programming language version 1.6 book - Part 37 of 189The Ring programming language version 1.6 book - Part 37 of 189
The Ring programming language version 1.6 book - Part 37 of 189Mahmoud Samir Fayed
 
The Ring programming language version 1.5.2 book - Part 34 of 181
The Ring programming language version 1.5.2 book - Part 34 of 181The Ring programming language version 1.5.2 book - Part 34 of 181
The Ring programming language version 1.5.2 book - Part 34 of 181Mahmoud Samir Fayed
 
The Ring programming language version 1.8 book - Part 40 of 202
The Ring programming language version 1.8 book - Part 40 of 202The Ring programming language version 1.8 book - Part 40 of 202
The Ring programming language version 1.8 book - Part 40 of 202Mahmoud Samir Fayed
 
The Ring programming language version 1.9 book - Part 42 of 210
The Ring programming language version 1.9 book - Part 42 of 210The Ring programming language version 1.9 book - Part 42 of 210
The Ring programming language version 1.9 book - Part 42 of 210Mahmoud Samir Fayed
 
The Ring programming language version 1.3 book - Part 25 of 88
The Ring programming language version 1.3 book - Part 25 of 88The Ring programming language version 1.3 book - Part 25 of 88
The Ring programming language version 1.3 book - Part 25 of 88Mahmoud Samir Fayed
 
Java 8 lambda expressions
Java 8 lambda expressionsJava 8 lambda expressions
Java 8 lambda expressionsLogan Chien
 
The Ring programming language version 1.3 book - Part 26 of 88
The Ring programming language version 1.3 book - Part 26 of 88The Ring programming language version 1.3 book - Part 26 of 88
The Ring programming language version 1.3 book - Part 26 of 88Mahmoud Samir Fayed
 
The Ring programming language version 1.7 book - Part 39 of 196
The Ring programming language version 1.7 book - Part 39 of 196The Ring programming language version 1.7 book - Part 39 of 196
The Ring programming language version 1.7 book - Part 39 of 196Mahmoud Samir Fayed
 
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
 
Extractors & Implicit conversions
Extractors & Implicit conversionsExtractors & Implicit conversions
Extractors & Implicit conversionsKnoldus Inc.
 
The Ring programming language version 1.5.4 book - Part 35 of 185
The Ring programming language version 1.5.4 book - Part 35 of 185The Ring programming language version 1.5.4 book - Part 35 of 185
The Ring programming language version 1.5.4 book - Part 35 of 185Mahmoud Samir Fayed
 
String in .net
String in .netString in .net
String in .netLarry Nung
 
Java 8 - Nuts and Bold - SFEIR Benelux
Java 8 - Nuts and Bold - SFEIR BeneluxJava 8 - Nuts and Bold - SFEIR Benelux
Java 8 - Nuts and Bold - SFEIR Beneluxyohanbeschi
 
The Ring programming language version 1.9 book - Part 43 of 210
The Ring programming language version 1.9 book - Part 43 of 210The Ring programming language version 1.9 book - Part 43 of 210
The Ring programming language version 1.9 book - Part 43 of 210Mahmoud Samir Fayed
 
Java, Up to Date Sources
Java, Up to Date SourcesJava, Up to Date Sources
Java, Up to Date Sources輝 子安
 

Similar to GeeCon 2016 - Beyond Lambdas, the Aftermath (20)

JFokus 2016 - Beyond Lambdas - the Aftermath
JFokus 2016 - Beyond Lambdas - the AftermathJFokus 2016 - Beyond Lambdas - the Aftermath
JFokus 2016 - Beyond Lambdas - the Aftermath
 
The Ring programming language version 1.6 book - Part 37 of 189
The Ring programming language version 1.6 book - Part 37 of 189The Ring programming language version 1.6 book - Part 37 of 189
The Ring programming language version 1.6 book - Part 37 of 189
 
The Ring programming language version 1.5.2 book - Part 34 of 181
The Ring programming language version 1.5.2 book - Part 34 of 181The Ring programming language version 1.5.2 book - Part 34 of 181
The Ring programming language version 1.5.2 book - Part 34 of 181
 
The Ring programming language version 1.8 book - Part 40 of 202
The Ring programming language version 1.8 book - Part 40 of 202The Ring programming language version 1.8 book - Part 40 of 202
The Ring programming language version 1.8 book - Part 40 of 202
 
The Ring programming language version 1.9 book - Part 42 of 210
The Ring programming language version 1.9 book - Part 42 of 210The Ring programming language version 1.9 book - Part 42 of 210
The Ring programming language version 1.9 book - Part 42 of 210
 
The Ring programming language version 1.3 book - Part 25 of 88
The Ring programming language version 1.3 book - Part 25 of 88The Ring programming language version 1.3 book - Part 25 of 88
The Ring programming language version 1.3 book - Part 25 of 88
 
Java 8 lambda expressions
Java 8 lambda expressionsJava 8 lambda expressions
Java 8 lambda expressions
 
The Ring programming language version 1.3 book - Part 26 of 88
The Ring programming language version 1.3 book - Part 26 of 88The Ring programming language version 1.3 book - Part 26 of 88
The Ring programming language version 1.3 book - Part 26 of 88
 
The Ring programming language version 1.7 book - Part 39 of 196
The Ring programming language version 1.7 book - Part 39 of 196The Ring programming language version 1.7 book - Part 39 of 196
The Ring programming language version 1.7 book - Part 39 of 196
 
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
 
Extractors & Implicit conversions
Extractors & Implicit conversionsExtractors & Implicit conversions
Extractors & Implicit conversions
 
The Ring programming language version 1.5.4 book - Part 35 of 185
The Ring programming language version 1.5.4 book - Part 35 of 185The Ring programming language version 1.5.4 book - Part 35 of 185
The Ring programming language version 1.5.4 book - Part 35 of 185
 
String in .net
String in .netString in .net
String in .net
 
Java 8 - Nuts and Bold - SFEIR Benelux
Java 8 - Nuts and Bold - SFEIR BeneluxJava 8 - Nuts and Bold - SFEIR Benelux
Java 8 - Nuts and Bold - SFEIR Benelux
 
The Ring programming language version 1.9 book - Part 43 of 210
The Ring programming language version 1.9 book - Part 43 of 210The Ring programming language version 1.9 book - Part 43 of 210
The Ring programming language version 1.9 book - Part 43 of 210
 
Java, Up to Date Sources
Java, Up to Date SourcesJava, Up to Date Sources
Java, Up to Date Sources
 
Class method
Class methodClass method
Class method
 
String slide
String slideString slide
String slide
 
Java VS Python
Java VS PythonJava VS Python
Java VS Python
 
Learn Matlab
Learn MatlabLearn Matlab
Learn Matlab
 

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, 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 (10)

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, 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

The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 

Recently uploaded (20)

The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 

GeeCon 2016 - Beyond Lambdas, the Aftermath

  • 2. About us… Daniel Sawano, Daniel Deogun Kraków, 11-13 May 2016 Daniel Deogun Daniel Sawano Stockholm - Gothenburg - Malmoe - Umea - New York
  • 3. [inert code here] Daniel Sawano, Daniel Deogun Kraków, 11-13 May 2016
  • 4. Optionals 1 7 final Oracle oracle = new Oracle(); 8 9 String _() { 10 final Advise advise = currentAdvise(); 11 12 if (advise != null) { 13 return advise.cheap(); 14 } 15 else { 16 return oracle.advise().expensive(); 17 } 18 }
  • 5. Optionals 1 25 final Oracle oracle = new Oracle(); 26 27 String _() { 28 final Advise advise = currentAdvise(); 29 30 return Optional.ofNullable(advise) 31 .map(Advise::cheap) 32 .orElse(oracle.advise().expensive()); 33 }
  • 6. Optionals 1 25 final Oracle oracle = new Oracle(); 26 27 String _() { 28 final Advise advise = currentAdvise(); 29 30 return Optional.ofNullable(advise) 31 .map(Advise::cheap) 32 .orElseGet( () -> oracle.advise().expensive()); 33 }
  • 7. 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 }
  • 8. 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 }
  • 9. 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 }
  • 10. Optionals 3 27 <T> void _(final Optional<T> argument) { 28 argument.map(a -> doSomething(a)); 29 }
  • 11. Optionals 3 25 <T> void _(final T argument) { 26 if (argument != null) { 27 doSomething(argument); 28 } 29 }
  • 12. Optionals 3 26 <T> void _(final T argument) { 27 doSomething(notNull(argument)); 28 }
  • 13. 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 }
  • 14. 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 }
  • 15. 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 }
  • 16. 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 }
  • 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 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 }
  • 18. 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 }
  • 19. 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 }
  • 20. 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 }
  • 21. 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 }
  • 22. 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 }
  • 23. 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 }
  • 24. 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 }
  • 25. 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 }
  • 26. 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. Q&A Daniel Sawano, Daniel Deogun Kraków, 11-13 May 2016 [Questions]
  • 28. Code examples can be found here: https://github.com/sawano/beyond-lambdas-the-aftermath Daniel Sawano, Daniel Deogun Kraków, 11-13 May 2016
  • 29. Thank you! @DanielSawano @DanielDeogun Daniel Sawano, Daniel Deogun Kraków, 11-13 May 2016