Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Real lifefp
1. Real Life FP
2
...zurück in der Java Welt
JUG Bielefeld, 19.11.14 1
2. Wie finden wir ein Element in einer
Collection?
JUG Bielefeld, 19.11.14 2
3. Java, the good ol‘ days
• Collections, wie war das noch?
• < Java5
– Iterator
– while(iterator.hasNext())
• > Java5
– for-each Loop
– for(Typ typ : typCollection)
JUG Bielefeld, 19.11.14 3
4. Java, the good ol‘ days
• ActionListener
• Comparator
• Runnable
• Callable
Gemeinsamkeiten?
JUG Bielefeld, 19.11.14 4
5. Java, the good ol‘ days
• Single Abstract Method Interfaces (SAM
Interfaces)
• Genau eine Methodendeklaration
• Wird häufig als anonyme innere Klasse
verwendet
JUG Bielefeld, 19.11.14 5
6. Java, the good ol‘ days
• Funktionale „Vorfahren“ in Java:
findElement(Collection, Predicate)
findElement(people, new Predicate() {
public boolean test(Person person) {
return person.getName().startsWith(...);
}
}
JUG Bielefeld, 19.11.14 6
13. Java 8
• Java wird funktional (unter anderem...)
• FunctionalInterface
• Und darauf aufbauend...
• Streams API
JUG Bielefeld, 19.11.14 13
14. Java 8
• Erinnert ihr euch an SAM?
– Anstatt:
new Predicate<T>() {
@Override
public boolean apply(T input) {
return input.isFoo();
}
}
– Einfach:
( input -> input.isFoo() )
JUG Bielefeld, 19.11.14 14
15. Java 8
• Wie geht das?
FunctionalInterface
– Ein funktionales Interface darf genau EINE
Methode deklarieren
– (...mit Ausnahme von default Methoden)
– Mittels der Annotation @FunctionalInterface wird
ein normales Interface funktional
JUG Bielefeld, 19.11.14 15
16. Java 8
• Beispiel Predicate:
@FunctionalInterface
public interface Predicate<T> {
boolean test(T t);
}
• Verwendung:
( obj -> obj.isFoo() )
JUG Bielefeld, 19.11.14 16
17. Java 8
• Streams API
– „A sequence of elements supporting sequential
and parallel aggregate operations“
– Stream pipelines bestehen aus
• Einer Datenquelle und
• 0 oder mehr intermediate
• und genau einer terminal Operation
JUG Bielefeld, 19.11.14 17
18. Java 8
Lets see some code!
JUG Bielefeld, 19.11.14 18
19. Quellen
• Google Guava:
– https://code.google.com/p/guava-libraries/wiki/GuavaExplained
– Und insbesondere:
– https://code.google.com/p/guava-libraries/wiki/FunctionalExplained
• Java 8
– http://www.oracle.com/technetwork/articles/java/lambda-1984522.html
– http://www.angelikalanger.com/Articles/EffectiveJava/70.Java8.FunctionalPro
g/70.Java8.FunctionalProg.html
• Code
– https://github.com/smartsquare/RealLifeFP
JUG Bielefeld, 19.11.14 19