Lambda expressions allow code to be passed as data in Java 8. The talk discusses myths and mistakes around lambda expressions, providing an introduction and examples. It emphasizes that syntax is less important than functional thinking and addresses common issues like debugging, testing and compiler errors. Functional thinking focuses on inputs and outputs rather than steps and requires practice to learn.
2. Learning FP is so much more than just
knowing what map/fold/filter/etc. do. It's
more like getting good at Portal :)
@copumpkin
3. Who am I?
Currently work at jClarity
Focus on performance diagnostics and
static analysis
Adopt a JSR (Date and Time + Lambdas)
Writing a book for O'Reilly Media on
Lambda Expressions in Java 8.
48. Very little TDD
Only a couple of developers used TDD or
unit tests
Maybe a reflection on general TDD
Maybe unfamiliarity with testing
functional code
49. How do I test this?
list.stream()
.map(x -> 1.0 / Math.ceil(1 + Math.pow(x) + Math.atan2(0, x)))
.collect(toList());
50. Approach 1: Test
surrounding function
Don't test the lambda
Test the method its surrounded by
Works well for simple lambdas
56. Compiler Error
java: reference to comparing is ambiguous both
method
<T>comparing(java.util.function.ToIntFunction< ? super T>)
in java.util.Comparator and method
<T,U>comparing(java.util.function.Function< ? super T,? extends U>)
in java.util.Comparator match
57. What happened?
// Generic object variant
public static <T, U extends Comparable< ? super U>>
Comparator<T>
comparing(Function< ? super T, ? extends U> keyExtractor)
// Specialised primitive variant
public static <T>
Comparator<T>
comparing(ToIntFunction< ? super T> keyExtractor)
58. Summary
Syntax important, but not in the way
people think
New approaches for debugging and
testing
Take care of overloads and compiler
error messages