Functional Programming in Java
Functional Programming in Java
and
Java 8
Ender Aydın Orak
elron.co
“Every problem in computer science can be solved
by adding another level of indirection.”
- David Wheeler
Programming Paradigms
• Machine Code
• Procedural Languages
• Functional Languages
• ML (1970s)
• OCaml (1996)
• …
FP: Why Now ?
• Moore’s Law runs out (in terms of CPU speeds)
• Distributed Computing
• Scalability
Benefits of FP
• Concurrency/Parallelism without tears
• Reusability, testability
• Clean * • Java
• Lisp/Scheme • Scala
• F# • JavaScript
* Pure
Sample:
Imperative Approach
class Player { String name; int score; Player(..){..} }
void declareWinner(Player p) {
System.out.println(p.name + “ is the winner! ”);
}
void declareWinner(Player p) {
System.out.println(p.name + “ is the winner! ”);
}
Reuse
System.out.println(players.stream().reduce(Play::maxScore));
Hands on examples