SlideShare uma empresa Scribd logo
1 de 25
Baixar para ler offline
λ
functions as values
var square = function(x) { return x * x };
var apply = function(data, func) {
return func(data);
}
console.log(apply(10, square));
Ang Java ay parang
kami ng ex ko...

..wala paring closure.
- anon
Anonymous Inner Classes
Collections.sort(personList, new Comparator<Person>(){
public int compare(Person p1, Person p2){
return p1.firstName.compareTo(p2.firstName);
}
});
Anonymous Inner Classes
Collections.sort(personList, new Comparator<Person>(){
public int compare(Person p1, Person p2){
return p1.firstName.compareTo(p2.firstName);
}
});

Lambda Expressions
Collections.sort(personList, (Person p1, Person p2) ->
p1.firstName.compareTo(p2.firstName));
Lambda Expressions
Collections.sort(personList, (Person p1, Person p2) ->
p1.firstName.compareTo(p2.firstName));

Lambda Exp. (shorter)
Collections.sort(personList,
(p1, p2) -> p1.firstName.compareTo(p2.firstName));
JEP 107
Bulk Data Operations
for Collections
(e.g filter/map/reduce)
filter
List<Employee> old = new ArrayList<Employee>();
for (Employee e : employeeList) {
if (e.age() > 60) {
old.add(e);
}
}
filter
List<Employee> old = new ArrayList<Employee>();
for (Employee e : employeeList) {
if (e.age() > 60) {
old.add(e);
}
}

List<Employee> old = employeeList.stream()
.filter(e -> e.age() > 60)
.collect(
Collectors.toCollection(
() -> new ArrayList<>()
)
);
filter
List<Employee> old = new ArrayList<Employee>();
for (Employee e : employeeList) {
if (e.age() > 60) {
old.add(e);
}
}

List<Employee> old = employeeList.stream()
.filter(e -> e.age() > 60)
.collect(Collectors.toCollection(
() -> new ArrayList<>()));
filter
List<Employee> old = new ArrayList<Employee>();
for (Employee e : employeeList) {
if (e.age() > 60) {
old.add(e);
}
}

List<Employee> old = employeeList.stream()
.filter(e -> e.age() > 60)
.collect(
Collectors.toCollection(
ArrayList::new
)
);
filter
List<Employee> old = new ArrayList<Employee>();
for (Employee e : employeeList) {
if (e.age() > 60) {
old.add(e);
}
}

List<Employee> old = employeeList.stream()
.filter(e -> e.age() > 60)
.collect(Collectors.toCollection(ArrayList::new));
filter
List<Employee> old = new ArrayList<Employee>();
for (Employee e : employeeList) {
if (e.age() > 60) {
old.add(e);
}
}

List<Employee> old = employeeList.stream()
.filter(e -> e.age() > 60)
.collect(Collectors.toList());
map
List<String> names = new ArrayList<String>();
for (Employee e : employeeList) {
names.add(e.firstName() + " " + e.lastName());
}
map
List<String> names = new ArrayList<String>();
for (Employee e : employeeList) {
names.add(e.firstName() + " " + e.lastName());
}

List<String> names = employeeList.stream()
.map(e -> e.firstName() + " " + e.lastName())
.collect(Collectors.toList());
reduce
BigDecimal totalSalary = BigDecimal.ZERO;
for (Employee e : employeeList) {
totalTax = totalTax.add(e.salary());
}
reduce
BigDecimal totalSalary = BigDecimal.ZERO;
for (Employee e : employeeList) {
totalTax = totalTax.add(e.salary());
}

BigDecimal totalSalary = employeeList.stream()
.reduce(BigDecimal.ZERO,
(sum, e) -> sum.add(e.salary()),
(bd1, bd2) -> bd1.add(bd2));
reduce
BigDecimal totalSalary = BigDecimal.ZERO;
for (Employee e : employeeList) {
totalTax = totalTax.add(e.salary());
}

BigDecimal totalSalary = employeeList.stream()
.reduce(BigDecimal.ZERO,
(sum, e) -> sum.add(e.salary()),
BigDecimal::add);
chaining
BigDecimal totalOldTax = employeeList.stream()
.filter(e -> e.age() > 60)
.map(e -> e.salary().multiply(e.taxRate()))
.reduce(BigDecimal.ZERO,
(sum, tax) -> sum.add(tax);
just like SQL
BigDecimal totalOldTax = employeeList.stream()
.filter(e -> e.age() > 60)
.map(e -> e.salary().multiply(e.taxRate()))
.reduce(BigDecimal.ZERO,
(sum, tax) -> sum.add(tax);

SELECT SUM(salary * tax_rate)
FROM employees
WHERE age > 60;
just like SQL
filter() => WHERE, GROUP BY
map()

=> SELECT, inline query

reduce() => aggregate functions
sort()

=> ORDER BY
λ
Java 8
Where to get Lambda
Project Page

http://openjdk.java.net/projects/lambda/

JDK8
http://jdk8.java.net/download.html

JDK8 w/ Lambda
http://jdk8.java.net/lambda/

NetBeans Nightly

http://bertram2.netbeans.org:8080/job/jdk8lambda/lastSuccessfulBuild/artifact/nbbuild/
Thank you for listening!

bryanbibat.net | @bry_bibat
speakerdeck.com/bryanbibat

Mais conteúdo relacionado

Mais procurados

Functional Patterns for the non-mathematician
Functional Patterns for the non-mathematicianFunctional Patterns for the non-mathematician
Functional Patterns for the non-mathematicianBrian Lonsdorf
 
Functional Programming for OO Programmers (part 2)
Functional Programming for OO Programmers (part 2)Functional Programming for OO Programmers (part 2)
Functional Programming for OO Programmers (part 2)Calvin Cheng
 
The Ring programming language version 1.10 book - Part 30 of 212
The Ring programming language version 1.10 book - Part 30 of 212The Ring programming language version 1.10 book - Part 30 of 212
The Ring programming language version 1.10 book - Part 30 of 212Mahmoud Samir Fayed
 
The Ring programming language version 1.4 book - Part 6 of 30
The Ring programming language version 1.4 book - Part 6 of 30The Ring programming language version 1.4 book - Part 6 of 30
The Ring programming language version 1.4 book - Part 6 of 30Mahmoud Samir Fayed
 
The Ring programming language version 1.6 book - Part 26 of 189
The Ring programming language version 1.6 book - Part 26 of 189The Ring programming language version 1.6 book - Part 26 of 189
The Ring programming language version 1.6 book - Part 26 of 189Mahmoud Samir Fayed
 
学生向けScalaハンズオンテキスト
学生向けScalaハンズオンテキスト学生向けScalaハンズオンテキスト
学生向けScalaハンズオンテキストOpt Technologies
 
学生向けScalaハンズオンテキスト part2
学生向けScalaハンズオンテキスト part2学生向けScalaハンズオンテキスト part2
学生向けScalaハンズオンテキスト part2Opt Technologies
 
Scala parallel-collections
Scala parallel-collectionsScala parallel-collections
Scala parallel-collectionsKnoldus Inc.
 
Drools5 Community Training Module 3 Drools Expert DRL Syntax
Drools5 Community Training Module 3 Drools Expert DRL SyntaxDrools5 Community Training Module 3 Drools Expert DRL Syntax
Drools5 Community Training Module 3 Drools Expert DRL SyntaxMauricio (Salaboy) Salatino
 
Remoção em Lista Simplesmente Encadeada
Remoção em Lista Simplesmente EncadeadaRemoção em Lista Simplesmente Encadeada
Remoção em Lista Simplesmente EncadeadaElaine Cecília Gatto
 
Kotlin Advanced - Apalon Kotlin Sprint Part 3
Kotlin Advanced - Apalon Kotlin Sprint Part 3Kotlin Advanced - Apalon Kotlin Sprint Part 3
Kotlin Advanced - Apalon Kotlin Sprint Part 3Kirill Rozov
 
The Ring programming language version 1.5.1 book - Part 21 of 180
The Ring programming language version 1.5.1 book - Part 21 of 180The Ring programming language version 1.5.1 book - Part 21 of 180
The Ring programming language version 1.5.1 book - Part 21 of 180Mahmoud Samir Fayed
 
Poor Man's Functional Programming
Poor Man's Functional ProgrammingPoor Man's Functional Programming
Poor Man's Functional ProgrammingDmitry Buzdin
 
Drools5 Community Training HandsOn 1 Drools DRL Syntax
Drools5 Community Training HandsOn 1 Drools DRL SyntaxDrools5 Community Training HandsOn 1 Drools DRL Syntax
Drools5 Community Training HandsOn 1 Drools DRL SyntaxMauricio (Salaboy) Salatino
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with ClojureDmitry Buzdin
 

Mais procurados (20)

Functional Patterns for the non-mathematician
Functional Patterns for the non-mathematicianFunctional Patterns for the non-mathematician
Functional Patterns for the non-mathematician
 
Functional Programming for OO Programmers (part 2)
Functional Programming for OO Programmers (part 2)Functional Programming for OO Programmers (part 2)
Functional Programming for OO Programmers (part 2)
 
Linq introduction
Linq introductionLinq introduction
Linq introduction
 
Millionways
MillionwaysMillionways
Millionways
 
Sixth session
Sixth sessionSixth session
Sixth session
 
The Ring programming language version 1.10 book - Part 30 of 212
The Ring programming language version 1.10 book - Part 30 of 212The Ring programming language version 1.10 book - Part 30 of 212
The Ring programming language version 1.10 book - Part 30 of 212
 
The Ring programming language version 1.4 book - Part 6 of 30
The Ring programming language version 1.4 book - Part 6 of 30The Ring programming language version 1.4 book - Part 6 of 30
The Ring programming language version 1.4 book - Part 6 of 30
 
The Ring programming language version 1.6 book - Part 26 of 189
The Ring programming language version 1.6 book - Part 26 of 189The Ring programming language version 1.6 book - Part 26 of 189
The Ring programming language version 1.6 book - Part 26 of 189
 
学生向けScalaハンズオンテキスト
学生向けScalaハンズオンテキスト学生向けScalaハンズオンテキスト
学生向けScalaハンズオンテキスト
 
学生向けScalaハンズオンテキスト part2
学生向けScalaハンズオンテキスト part2学生向けScalaハンズオンテキスト part2
学生向けScalaハンズオンテキスト part2
 
Oh Composable World!
Oh Composable World!Oh Composable World!
Oh Composable World!
 
ScalaMeter 2014
ScalaMeter 2014ScalaMeter 2014
ScalaMeter 2014
 
Scala parallel-collections
Scala parallel-collectionsScala parallel-collections
Scala parallel-collections
 
Drools5 Community Training Module 3 Drools Expert DRL Syntax
Drools5 Community Training Module 3 Drools Expert DRL SyntaxDrools5 Community Training Module 3 Drools Expert DRL Syntax
Drools5 Community Training Module 3 Drools Expert DRL Syntax
 
Remoção em Lista Simplesmente Encadeada
Remoção em Lista Simplesmente EncadeadaRemoção em Lista Simplesmente Encadeada
Remoção em Lista Simplesmente Encadeada
 
Kotlin Advanced - Apalon Kotlin Sprint Part 3
Kotlin Advanced - Apalon Kotlin Sprint Part 3Kotlin Advanced - Apalon Kotlin Sprint Part 3
Kotlin Advanced - Apalon Kotlin Sprint Part 3
 
The Ring programming language version 1.5.1 book - Part 21 of 180
The Ring programming language version 1.5.1 book - Part 21 of 180The Ring programming language version 1.5.1 book - Part 21 of 180
The Ring programming language version 1.5.1 book - Part 21 of 180
 
Poor Man's Functional Programming
Poor Man's Functional ProgrammingPoor Man's Functional Programming
Poor Man's Functional Programming
 
Drools5 Community Training HandsOn 1 Drools DRL Syntax
Drools5 Community Training HandsOn 1 Drools DRL SyntaxDrools5 Community Training HandsOn 1 Drools DRL Syntax
Drools5 Community Training HandsOn 1 Drools DRL Syntax
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
 

Destaque

My first experience with lambda expressions in java
My first experience with lambda expressions in javaMy first experience with lambda expressions in java
My first experience with lambda expressions in javaScheidt & Bachmann
 
Lambda expressions
Lambda expressionsLambda expressions
Lambda expressionsDoron Gold
 
Java Logging discussion Log4j,Slf4j
Java Logging discussion Log4j,Slf4jJava Logging discussion Log4j,Slf4j
Java Logging discussion Log4j,Slf4jRajiv Gupta
 
Lambda expressions
Lambda expressionsLambda expressions
Lambda expressionsYuriy Seniuk
 
Simplifying java with lambdas (short)
Simplifying java with lambdas (short)Simplifying java with lambdas (short)
Simplifying java with lambdas (short)RichardWarburton
 
OCP Java SE 8 Exam - Sample Questions - Lambda Expressions
OCP Java SE 8 Exam - Sample Questions - Lambda Expressions OCP Java SE 8 Exam - Sample Questions - Lambda Expressions
OCP Java SE 8 Exam - Sample Questions - Lambda Expressions Ganesh Samarthyam
 
Lambda Expressions in Java 8
Lambda Expressions in Java 8Lambda Expressions in Java 8
Lambda Expressions in Java 8icarter09
 
Fun with lambda expressions
Fun with lambda expressionsFun with lambda expressions
Fun with lambda expressionsMike Melusky
 
Java 8 lambdas expressions
Java 8 lambdas expressionsJava 8 lambdas expressions
Java 8 lambdas expressionsLars Lemos
 
Programming with Lambda Expressions in Java
Programming with Lambda Expressions in Java Programming with Lambda Expressions in Java
Programming with Lambda Expressions in Java langer4711
 
Lambda: A Peek Under The Hood - Brian Goetz
Lambda: A Peek Under The Hood - Brian GoetzLambda: A Peek Under The Hood - Brian Goetz
Lambda: A Peek Under The Hood - Brian GoetzJAX London
 
Lambda Expressions in Java
Lambda Expressions in JavaLambda Expressions in Java
Lambda Expressions in JavaErhan Bagdemir
 
Introduction of Java 8 with emphasis on Lambda Expressions and Streams
Introduction of Java 8 with emphasis on Lambda Expressions and StreamsIntroduction of Java 8 with emphasis on Lambda Expressions and Streams
Introduction of Java 8 with emphasis on Lambda Expressions and StreamsEmiel Paasschens
 
Understanding Java 8 Lambdas and Streams - Part 1 - Lambda Calculus, Lambda...
Understanding Java 8 Lambdas and Streams - Part 1 - Lambda Calculus, Lambda...Understanding Java 8 Lambdas and Streams - Part 1 - Lambda Calculus, Lambda...
Understanding Java 8 Lambdas and Streams - Part 1 - Lambda Calculus, Lambda...Philip Schwarz
 
Productive Programming in Java 8 - with Lambdas and Streams
Productive Programming in Java 8 - with Lambdas and Streams Productive Programming in Java 8 - with Lambdas and Streams
Productive Programming in Java 8 - with Lambdas and Streams Ganesh Samarthyam
 
Java 8 Lambda Expressions & Streams
Java 8 Lambda Expressions & StreamsJava 8 Lambda Expressions & Streams
Java 8 Lambda Expressions & StreamsNewCircle Training
 

Destaque (20)

My first experience with lambda expressions in java
My first experience with lambda expressions in javaMy first experience with lambda expressions in java
My first experience with lambda expressions in java
 
Lambda expressions
Lambda expressionsLambda expressions
Lambda expressions
 
Java Logging discussion Log4j,Slf4j
Java Logging discussion Log4j,Slf4jJava Logging discussion Log4j,Slf4j
Java Logging discussion Log4j,Slf4j
 
Lambda expressions
Lambda expressionsLambda expressions
Lambda expressions
 
Simplifying java with lambdas (short)
Simplifying java with lambdas (short)Simplifying java with lambdas (short)
Simplifying java with lambdas (short)
 
OCP Java SE 8 Exam - Sample Questions - Lambda Expressions
OCP Java SE 8 Exam - Sample Questions - Lambda Expressions OCP Java SE 8 Exam - Sample Questions - Lambda Expressions
OCP Java SE 8 Exam - Sample Questions - Lambda Expressions
 
Lambda Expressions in Java 8
Lambda Expressions in Java 8Lambda Expressions in Java 8
Lambda Expressions in Java 8
 
Fun with lambda expressions
Fun with lambda expressionsFun with lambda expressions
Fun with lambda expressions
 
Java 8 lambdas expressions
Java 8 lambdas expressionsJava 8 lambdas expressions
Java 8 lambdas expressions
 
Programming with Lambda Expressions in Java
Programming with Lambda Expressions in Java Programming with Lambda Expressions in Java
Programming with Lambda Expressions in Java
 
SLF4J Explained........
SLF4J Explained........SLF4J Explained........
SLF4J Explained........
 
Lambda: A Peek Under The Hood - Brian Goetz
Lambda: A Peek Under The Hood - Brian GoetzLambda: A Peek Under The Hood - Brian Goetz
Lambda: A Peek Under The Hood - Brian Goetz
 
Lambda Expressions in Java
Lambda Expressions in JavaLambda Expressions in Java
Lambda Expressions in Java
 
Reflection
ReflectionReflection
Reflection
 
Lambda expressions
Lambda expressionsLambda expressions
Lambda expressions
 
Introduction of Java 8 with emphasis on Lambda Expressions and Streams
Introduction of Java 8 with emphasis on Lambda Expressions and StreamsIntroduction of Java 8 with emphasis on Lambda Expressions and Streams
Introduction of Java 8 with emphasis on Lambda Expressions and Streams
 
Java 8 lambda
Java 8 lambdaJava 8 lambda
Java 8 lambda
 
Understanding Java 8 Lambdas and Streams - Part 1 - Lambda Calculus, Lambda...
Understanding Java 8 Lambdas and Streams - Part 1 - Lambda Calculus, Lambda...Understanding Java 8 Lambdas and Streams - Part 1 - Lambda Calculus, Lambda...
Understanding Java 8 Lambdas and Streams - Part 1 - Lambda Calculus, Lambda...
 
Productive Programming in Java 8 - with Lambdas and Streams
Productive Programming in Java 8 - with Lambdas and Streams Productive Programming in Java 8 - with Lambdas and Streams
Productive Programming in Java 8 - with Lambdas and Streams
 
Java 8 Lambda Expressions & Streams
Java 8 Lambda Expressions & StreamsJava 8 Lambda Expressions & Streams
Java 8 Lambda Expressions & Streams
 

Semelhante a Lambda Expressions in Java 8

pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfHiroshi Ono
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfHiroshi Ono
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfHiroshi Ono
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfHiroshi Ono
 
Idiomatic Kotlin
Idiomatic KotlinIdiomatic Kotlin
Idiomatic Kotlinintelliyole
 
Scala in a Java 8 World
Scala in a Java 8 WorldScala in a Java 8 World
Scala in a Java 8 WorldDaniel Blyth
 
07. Java Array, Set and Maps
07.  Java Array, Set and Maps07.  Java Array, Set and Maps
07. Java Array, Set and MapsIntro C# Book
 
Rewriting Java In Scala
Rewriting Java In ScalaRewriting Java In Scala
Rewriting Java In ScalaSkills Matter
 
Kotlin collections
Kotlin collectionsKotlin collections
Kotlin collectionsMyeongin Woo
 
JBUG 11 - Scala For Java Programmers
JBUG 11 - Scala For Java ProgrammersJBUG 11 - Scala For Java Programmers
JBUG 11 - Scala For Java ProgrammersTikal Knowledge
 
1.2 Scala Basics
1.2 Scala Basics1.2 Scala Basics
1.2 Scala Basicsretronym
 
Scala - THE language for Big Data
Scala - THE language for Big DataScala - THE language for Big Data
Scala - THE language for Big DataTzach Zohar
 
The Ring programming language version 1.7 book - Part 26 of 196
The Ring programming language version 1.7 book - Part 26 of 196The Ring programming language version 1.7 book - Part 26 of 196
The Ring programming language version 1.7 book - Part 26 of 196Mahmoud Samir Fayed
 
iRODS Rule Language Cheat Sheet
iRODS Rule Language Cheat SheetiRODS Rule Language Cheat Sheet
iRODS Rule Language Cheat SheetSamuel Lampa
 
FUNctional Programming in Java 8
FUNctional Programming in Java 8FUNctional Programming in Java 8
FUNctional Programming in Java 8Richard Walker
 

Semelhante a Lambda Expressions in Java 8 (20)

A bit about Scala
A bit about ScalaA bit about Scala
A bit about Scala
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
 
Idiomatic Kotlin
Idiomatic KotlinIdiomatic Kotlin
Idiomatic Kotlin
 
Scala in a Java 8 World
Scala in a Java 8 WorldScala in a Java 8 World
Scala in a Java 8 World
 
List out of lambda
List out of lambdaList out of lambda
List out of lambda
 
Scala 2013 review
Scala 2013 reviewScala 2013 review
Scala 2013 review
 
07. Java Array, Set and Maps
07.  Java Array, Set and Maps07.  Java Array, Set and Maps
07. Java Array, Set and Maps
 
Rewriting Java In Scala
Rewriting Java In ScalaRewriting Java In Scala
Rewriting Java In Scala
 
Kotlin collections
Kotlin collectionsKotlin collections
Kotlin collections
 
JBUG 11 - Scala For Java Programmers
JBUG 11 - Scala For Java ProgrammersJBUG 11 - Scala For Java Programmers
JBUG 11 - Scala For Java Programmers
 
1.2 Scala Basics
1.2 Scala Basics1.2 Scala Basics
1.2 Scala Basics
 
Scala - THE language for Big Data
Scala - THE language for Big DataScala - THE language for Big Data
Scala - THE language for Big Data
 
The Ring programming language version 1.7 book - Part 26 of 196
The Ring programming language version 1.7 book - Part 26 of 196The Ring programming language version 1.7 book - Part 26 of 196
The Ring programming language version 1.7 book - Part 26 of 196
 
iRODS Rule Language Cheat Sheet
iRODS Rule Language Cheat SheetiRODS Rule Language Cheat Sheet
iRODS Rule Language Cheat Sheet
 
Python : Functions
Python : FunctionsPython : Functions
Python : Functions
 
FUNctional Programming in Java 8
FUNctional Programming in Java 8FUNctional Programming in Java 8
FUNctional Programming in Java 8
 
Java Generics
Java GenericsJava Generics
Java Generics
 

Mais de bryanbibat

Static Sites in Ruby
Static Sites in RubyStatic Sites in Ruby
Static Sites in Rubybryanbibat
 
So You Want to Teach Ruby and Rails...
So You Want to Teach Ruby and Rails...So You Want to Teach Ruby and Rails...
So You Want to Teach Ruby and Rails...bryanbibat
 
Git Basics (Professionals)
 Git Basics (Professionals) Git Basics (Professionals)
Git Basics (Professionals)bryanbibat
 
Upgrading to Ruby 2.1, Rails 4.0, Bootstrap 3.0
Upgrading to Ruby 2.1, Rails 4.0, Bootstrap 3.0Upgrading to Ruby 2.1, Rails 4.0, Bootstrap 3.0
Upgrading to Ruby 2.1, Rails 4.0, Bootstrap 3.0bryanbibat
 
Version Control with Git for Beginners
Version Control with Git for BeginnersVersion Control with Git for Beginners
Version Control with Git for Beginnersbryanbibat
 
Rails is Easy*
Rails is Easy*Rails is Easy*
Rails is Easy*bryanbibat
 
Things Future IT Students Should Know (But Don't)
Things Future IT Students Should Know (But Don't)Things Future IT Students Should Know (But Don't)
Things Future IT Students Should Know (But Don't)bryanbibat
 
Things IT Undergrads Should Know (But Don't)
Things IT Undergrads Should Know (But Don't)Things IT Undergrads Should Know (But Don't)
Things IT Undergrads Should Know (But Don't)bryanbibat
 
From Novice to Expert: A Pragmatic Approach to Learning
From Novice to Expert: A Pragmatic Approach to LearningFrom Novice to Expert: A Pragmatic Approach to Learning
From Novice to Expert: A Pragmatic Approach to Learningbryanbibat
 
Preparing for the WebGeek DevCup
Preparing for the WebGeek DevCupPreparing for the WebGeek DevCup
Preparing for the WebGeek DevCupbryanbibat
 
Productive text editing with Vim
Productive text editing with VimProductive text editing with Vim
Productive text editing with Vimbryanbibat
 
Ruby and Rails by Example (GeekCamp edition)
Ruby and Rails by Example (GeekCamp edition)Ruby and Rails by Example (GeekCamp edition)
Ruby and Rails by Example (GeekCamp edition)bryanbibat
 
Latest Trends in Web Technologies
Latest Trends in Web TechnologiesLatest Trends in Web Technologies
Latest Trends in Web Technologiesbryanbibat
 
Virtualization
VirtualizationVirtualization
Virtualizationbryanbibat
 
Some Myths in Software Development
Some Myths in Software DevelopmentSome Myths in Software Development
Some Myths in Software Developmentbryanbibat
 
Latest Trends in Open Source Web Technologies
Latest Trends in Open Source Web TechnologiesLatest Trends in Open Source Web Technologies
Latest Trends in Open Source Web Technologiesbryanbibat
 
What it takes to be a Web Developer
What it takes to be a Web DeveloperWhat it takes to be a Web Developer
What it takes to be a Web Developerbryanbibat
 
Ruby and Rails by example
Ruby and Rails by exampleRuby and Rails by example
Ruby and Rails by examplebryanbibat
 

Mais de bryanbibat (20)

Hd 10 japan
Hd 10 japanHd 10 japan
Hd 10 japan
 
Static Sites in Ruby
Static Sites in RubyStatic Sites in Ruby
Static Sites in Ruby
 
So You Want to Teach Ruby and Rails...
So You Want to Teach Ruby and Rails...So You Want to Teach Ruby and Rails...
So You Want to Teach Ruby and Rails...
 
Git Basics (Professionals)
 Git Basics (Professionals) Git Basics (Professionals)
Git Basics (Professionals)
 
Upgrading to Ruby 2.1, Rails 4.0, Bootstrap 3.0
Upgrading to Ruby 2.1, Rails 4.0, Bootstrap 3.0Upgrading to Ruby 2.1, Rails 4.0, Bootstrap 3.0
Upgrading to Ruby 2.1, Rails 4.0, Bootstrap 3.0
 
Version Control with Git for Beginners
Version Control with Git for BeginnersVersion Control with Git for Beginners
Version Control with Git for Beginners
 
Rails is Easy*
Rails is Easy*Rails is Easy*
Rails is Easy*
 
Things Future IT Students Should Know (But Don't)
Things Future IT Students Should Know (But Don't)Things Future IT Students Should Know (But Don't)
Things Future IT Students Should Know (But Don't)
 
Things IT Undergrads Should Know (But Don't)
Things IT Undergrads Should Know (But Don't)Things IT Undergrads Should Know (But Don't)
Things IT Undergrads Should Know (But Don't)
 
From Novice to Expert: A Pragmatic Approach to Learning
From Novice to Expert: A Pragmatic Approach to LearningFrom Novice to Expert: A Pragmatic Approach to Learning
From Novice to Expert: A Pragmatic Approach to Learning
 
Preparing for the WebGeek DevCup
Preparing for the WebGeek DevCupPreparing for the WebGeek DevCup
Preparing for the WebGeek DevCup
 
Productive text editing with Vim
Productive text editing with VimProductive text editing with Vim
Productive text editing with Vim
 
Ruby and Rails by Example (GeekCamp edition)
Ruby and Rails by Example (GeekCamp edition)Ruby and Rails by Example (GeekCamp edition)
Ruby and Rails by Example (GeekCamp edition)
 
Latest Trends in Web Technologies
Latest Trends in Web TechnologiesLatest Trends in Web Technologies
Latest Trends in Web Technologies
 
Virtualization
VirtualizationVirtualization
Virtualization
 
Some Myths in Software Development
Some Myths in Software DevelopmentSome Myths in Software Development
Some Myths in Software Development
 
Latest Trends in Open Source Web Technologies
Latest Trends in Open Source Web TechnologiesLatest Trends in Open Source Web Technologies
Latest Trends in Open Source Web Technologies
 
What it takes to be a Web Developer
What it takes to be a Web DeveloperWhat it takes to be a Web Developer
What it takes to be a Web Developer
 
Ruby and Rails by example
Ruby and Rails by exampleRuby and Rails by example
Ruby and Rails by example
 
Ruby on Rails
Ruby on RailsRuby on Rails
Ruby on Rails
 

Último

TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 

Último (20)

TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 

Lambda Expressions in Java 8

  • 1. λ
  • 2.
  • 3. functions as values var square = function(x) { return x * x }; var apply = function(data, func) { return func(data); } console.log(apply(10, square));
  • 4. Ang Java ay parang kami ng ex ko... ..wala paring closure. - anon
  • 5. Anonymous Inner Classes Collections.sort(personList, new Comparator<Person>(){ public int compare(Person p1, Person p2){ return p1.firstName.compareTo(p2.firstName); } });
  • 6. Anonymous Inner Classes Collections.sort(personList, new Comparator<Person>(){ public int compare(Person p1, Person p2){ return p1.firstName.compareTo(p2.firstName); } }); Lambda Expressions Collections.sort(personList, (Person p1, Person p2) -> p1.firstName.compareTo(p2.firstName));
  • 7. Lambda Expressions Collections.sort(personList, (Person p1, Person p2) -> p1.firstName.compareTo(p2.firstName)); Lambda Exp. (shorter) Collections.sort(personList, (p1, p2) -> p1.firstName.compareTo(p2.firstName));
  • 8. JEP 107 Bulk Data Operations for Collections (e.g filter/map/reduce)
  • 9. filter List<Employee> old = new ArrayList<Employee>(); for (Employee e : employeeList) { if (e.age() > 60) { old.add(e); } }
  • 10. filter List<Employee> old = new ArrayList<Employee>(); for (Employee e : employeeList) { if (e.age() > 60) { old.add(e); } } List<Employee> old = employeeList.stream() .filter(e -> e.age() > 60) .collect( Collectors.toCollection( () -> new ArrayList<>() ) );
  • 11. filter List<Employee> old = new ArrayList<Employee>(); for (Employee e : employeeList) { if (e.age() > 60) { old.add(e); } } List<Employee> old = employeeList.stream() .filter(e -> e.age() > 60) .collect(Collectors.toCollection( () -> new ArrayList<>()));
  • 12. filter List<Employee> old = new ArrayList<Employee>(); for (Employee e : employeeList) { if (e.age() > 60) { old.add(e); } } List<Employee> old = employeeList.stream() .filter(e -> e.age() > 60) .collect( Collectors.toCollection( ArrayList::new ) );
  • 13. filter List<Employee> old = new ArrayList<Employee>(); for (Employee e : employeeList) { if (e.age() > 60) { old.add(e); } } List<Employee> old = employeeList.stream() .filter(e -> e.age() > 60) .collect(Collectors.toCollection(ArrayList::new));
  • 14. filter List<Employee> old = new ArrayList<Employee>(); for (Employee e : employeeList) { if (e.age() > 60) { old.add(e); } } List<Employee> old = employeeList.stream() .filter(e -> e.age() > 60) .collect(Collectors.toList());
  • 15. map List<String> names = new ArrayList<String>(); for (Employee e : employeeList) { names.add(e.firstName() + " " + e.lastName()); }
  • 16. map List<String> names = new ArrayList<String>(); for (Employee e : employeeList) { names.add(e.firstName() + " " + e.lastName()); } List<String> names = employeeList.stream() .map(e -> e.firstName() + " " + e.lastName()) .collect(Collectors.toList());
  • 17. reduce BigDecimal totalSalary = BigDecimal.ZERO; for (Employee e : employeeList) { totalTax = totalTax.add(e.salary()); }
  • 18. reduce BigDecimal totalSalary = BigDecimal.ZERO; for (Employee e : employeeList) { totalTax = totalTax.add(e.salary()); } BigDecimal totalSalary = employeeList.stream() .reduce(BigDecimal.ZERO, (sum, e) -> sum.add(e.salary()), (bd1, bd2) -> bd1.add(bd2));
  • 19. reduce BigDecimal totalSalary = BigDecimal.ZERO; for (Employee e : employeeList) { totalTax = totalTax.add(e.salary()); } BigDecimal totalSalary = employeeList.stream() .reduce(BigDecimal.ZERO, (sum, e) -> sum.add(e.salary()), BigDecimal::add);
  • 20. chaining BigDecimal totalOldTax = employeeList.stream() .filter(e -> e.age() > 60) .map(e -> e.salary().multiply(e.taxRate())) .reduce(BigDecimal.ZERO, (sum, tax) -> sum.add(tax);
  • 21. just like SQL BigDecimal totalOldTax = employeeList.stream() .filter(e -> e.age() > 60) .map(e -> e.salary().multiply(e.taxRate())) .reduce(BigDecimal.ZERO, (sum, tax) -> sum.add(tax); SELECT SUM(salary * tax_rate) FROM employees WHERE age > 60;
  • 22. just like SQL filter() => WHERE, GROUP BY map() => SELECT, inline query reduce() => aggregate functions sort() => ORDER BY
  • 24. Where to get Lambda Project Page http://openjdk.java.net/projects/lambda/ JDK8 http://jdk8.java.net/download.html JDK8 w/ Lambda http://jdk8.java.net/lambda/ NetBeans Nightly http://bertram2.netbeans.org:8080/job/jdk8lambda/lastSuccessfulBuild/artifact/nbbuild/
  • 25. Thank you for listening! bryanbibat.net | @bry_bibat speakerdeck.com/bryanbibat