SlideShare a Scribd company logo
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 programs
Mukesh 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 programms
Yasir 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 entreprise
SOAT
 
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
Mahmoud Samir Fayed
 
.net progrmming part2
.net progrmming part2.net progrmming part2
.net progrmming part2
Dr.M.Karthika parthasarathy
 
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
Mahmoud 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 84
Mahmoud 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 84
Mahmoud Samir Fayed
 
Java Performance Puzzlers
Java Performance PuzzlersJava Performance Puzzlers
Java Performance Puzzlers
Doug Hawkins
 
Java_practical_handbook
Java_practical_handbookJava_practical_handbook
Java_practical_handbook
Manusha Dilan
 
RMI Java Programming Lab Manual 2019
RMI Java Programming Lab Manual 2019RMI Java Programming Lab Manual 2019
RMI Java Programming Lab Manual 2019
Gebreigziabher Ab
 
Java PRACTICAL file
Java PRACTICAL fileJava PRACTICAL file
Java PRACTICAL file
RACHIT_GUPTA
 
Dsprograms(2nd cse)
Dsprograms(2nd cse)Dsprograms(2nd cse)
Dsprograms(2nd cse)
Pradeep Kumar Reddy Reddy
 
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
Mahmoud 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 Aftermath
Daniel 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 Profile
Chuck Brooks
 
Becoming current spring_14
Becoming current spring_14Becoming current spring_14
Becoming current spring_14
countrygirl3
 
Proyeksi vektor aji santoso ( 31 ) msp
Proyeksi vektor aji santoso ( 31 ) mspProyeksi vektor aji santoso ( 31 ) msp
Proyeksi vektor aji santoso ( 31 ) msp
laurisahat07
 
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
Sorin 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 2016
Netpulse
 
Customer service careers
Customer service careersCustomer service careers
Customer service careers
crew
 
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
WordCamp Sydney
 
Pourquoi les evenements sont importants
Pourquoi les evenements sont importantsPourquoi les evenements sont importants
Pourquoi les evenements sont importants
Emilien 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 Literacy
Dean 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
 
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...
PSST (opinions et tendances 2.0) par jeremy dumont
 
Personal and Personalized Learning
Personal and Personalized LearningPersonal and Personalized Learning
Personal and Personalized Learning
Dean Shareski
 
Junho jardim
Junho jardimJunho jardim
Junho jardim
patronatobonanca
 
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
Patrick Hourihan
 
Curriculum vitae sv
Curriculum vitae svCurriculum vitae sv
Curriculum vitae sv
Bo 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 Aftermath
Daniel 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 189
Mahmoud 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 181
Mahmoud 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 202
Mahmoud 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 210
Mahmoud 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 88
Mahmoud Samir Fayed
 
Java 8 lambda expressions
Java 8 lambda expressionsJava 8 lambda expressions
Java 8 lambda expressions
Logan 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 88
Mahmoud 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 196
Mahmoud 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.docx
cravennichole326
 
Extractors & Implicit conversions
Extractors & Implicit conversionsExtractors & Implicit conversions
Extractors & Implicit conversions
Knoldus 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 185
Mahmoud 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 Benelux
yohanbeschi
 
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
Mahmoud Samir Fayed
 
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
kamal kotecha
 
String slide
String slideString slide
String slide
Daman Toor
 
Java VS Python
Java VS PythonJava VS Python
Java VS Python
Simone Federici
 

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 Software
Daniel 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 Software
Daniel Sawano
 
DevDays LT 2017 - Secure by Design
DevDays LT 2017 - Secure by DesignDevDays LT 2017 - Secure by Design
DevDays LT 2017 - Secure by Design
Daniel Sawano
 
Devoxx, MA, 2015, Failing Continuous Delivery
Devoxx, MA, 2015, Failing Continuous DeliveryDevoxx, MA, 2015, Failing Continuous Delivery
Devoxx, MA, 2015, Failing Continuous Delivery
Daniel Sawano
 
Failing Continuous Delivery, Agile Prague 2015
Failing Continuous Delivery, Agile Prague 2015Failing Continuous Delivery, Agile Prague 2015
Failing Continuous Delivery, Agile Prague 2015
Daniel Sawano
 
Failing Continuous Delivery, Devoxx Poland, 2015
Failing Continuous Delivery, Devoxx Poland, 2015Failing Continuous Delivery, Devoxx Poland, 2015
Failing Continuous Delivery, Devoxx Poland, 2015
Daniel Sawano
 
Things Every Professional Programmer Should Know
Things Every Professional Programmer Should KnowThings Every Professional Programmer Should Know
Things Every Professional Programmer Should Know
Daniel Sawano
 
Failing Continuous Delivery, JDays, 2015
Failing Continuous Delivery, JDays, 2015Failing Continuous Delivery, JDays, 2015
Failing Continuous Delivery, JDays, 2015
Daniel Sawano
 
Akka Made Our Day
Akka Made Our DayAkka Made Our Day
Akka Made Our Day
Daniel Sawano
 
Reactive Programming With Akka - Lessons Learned
Reactive Programming With Akka - Lessons LearnedReactive Programming With Akka - Lessons Learned
Reactive Programming With Akka - Lessons Learned
Daniel 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

GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
Alina Yurenko
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeA Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
Aftab Hussain
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Crescat
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
Boni García
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
Game Development with Unity3D (Game Development lecture 3)
Game Development  with Unity3D (Game Development lecture 3)Game Development  with Unity3D (Game Development lecture 3)
Game Development with Unity3D (Game Development lecture 3)
abdulrafaychaudhry
 
Nidhi Software Price. Fact , Costs, Tips
Nidhi Software Price. Fact , Costs, TipsNidhi Software Price. Fact , Costs, Tips
Nidhi Software Price. Fact , Costs, Tips
vrstrong314
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
Neo4j
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
Drona Infotech
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
lorraineandreiamcidl
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
Łukasz Chruściel
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
Shane Coughlan
 

Recently uploaded (20)

GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeA Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
Game Development with Unity3D (Game Development lecture 3)
Game Development  with Unity3D (Game Development lecture 3)Game Development  with Unity3D (Game Development lecture 3)
Game Development with Unity3D (Game Development lecture 3)
 
Nidhi Software Price. Fact , Costs, Tips
Nidhi Software Price. Fact , Costs, TipsNidhi Software Price. Fact , Costs, Tips
Nidhi Software Price. Fact , Costs, Tips
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
 

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