0% found this document useful (0 votes)
40 views12 pages

Clean Lambdas: Enterprise Java Training

Uploaded by

Monika
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views12 pages

Clean Lambdas: Enterprise Java Training

Uploaded by

Monika
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Enterprise Java Training

Clean Lambdas
Victor Rentea
19 june 2017, Barcelona © Copyright Victor Rentea 2017

VictorRentea.ro
[email protected]
@victorrentea
VictorRentea.ro
Victor Rentea
Consultant, Technical Lead
Lead Architect for major IBM client Independent Trainer
1000+ devs. 1500+ hrs. 5 yrs.
Clean Code Evangelist
Spring, JavaEE, JPA/Hibernate
Speaker Clean Code, Architectures
Design Patterns
TDD, Coach, Coding Dojos
Java Performance, more...
[email protected] @victorrentea VictorRentea.ro
2 VictorRentea.ro
Clean Lambdas

Why Lambdas ?
They are cool

3 VictorRentea.ro
But is the Code still Clean ?

4 VictorRentea.ro
Clean Lambdas

Expressive ?
.filter(MyObj::isActive)
or My own little
Clean Lambdas study
Cryptic ?
.filter(order -> order.getOrderLines().stream()
.filter(line->line.isActive()).findFirst().isPresent())
.map(Order::getOrderLines)
.flatMap(List::stream)
.filter(orderLine -> orderLine.getCount().compareTo(new BigDecimal(“2”))
.collect(groupingBy(OrderLine::getProduct,
groupingBy(line->line.getOrder().getPaymentMethod(),
summingInt(OrderLine::getCount);

5 VictorRentea.ro
public static Predicate<Order> deliveryDueBefore(Date date) {
Local Variables Encapsulate Predicates
}
return order -> order.getDeliveryDueDate().before(date);

Functions returning Predicates


Predicate<Order> needsTracking = order -> order.getPrice() > 1000;
Set<Customer> customersToNotify = orders.stream()
.filter(deliveryDueBefore(warningDate).or(needsTracking))
.filter(this::hasLinesNotInStock)
.map(Order::getCustomer)
.collect(toSet());

public boolean hasLinesNotInStock(Order order) { class OrderLine { ...


return order.getOrderLines().stream() public boolean isNotInStock() {
.anyMatch(OrderLine::isNotInStock); return status != Status.IN_STOCK;
} }
}
Helper methods in this:: Helper getters in entities
6 http://bit.ly/2dFf2fi VictorRentea.ro
Clean Code in Java8

Try some lib?


if checked Ex, >2 params
jOOL, vavr,…

For more, check-out the screen cast of my Clean Lambdas workshop


7 at Voxxed Bucharest 2017, on my website  VictorRentea.ro
Peer Review!
Pair Programming

8 VictorRentea.ro
Peer Review!
Pair Programming
9 VictorRentea.ro
Where
can I read
LET’S
more ?
How to PRACTICE
apply all !!!
this in my
legacy
code
??

12 ©
 Screen cast of my “Clean
Lambdas Workshop” at
VoxxedDays Bucharest

13
Check out my tweets for more
VictorRentea.ro
https://github.com/victorrentea/clean-lambdas-jbcnconf.git

Enterprise Java Training

Clean Lambdas
Victor Rentea
19 june 2017, Barcelona © Copyright Victor Rentea 2017

VictorRentea.ro
[email protected]
@victorrentea
VictorRentea.ro

You might also like