SlideShare ist ein Scribd-Unternehmen logo
1 von 14
Downloaden Sie, um offline zu lesen
Lambdas 
HOL 
Speaker: 
Oleg 
Tsal-­‐Tsalko(@tsaltsol)
About 
me 
Oleg 
Tsal-­‐Tsalko 
Lead 
So:ware 
Engineer 
at 
EPAM 
Systems. 
Speaker, 
acEve 
member 
of 
Kiev 
JUG. 
ParEcipate 
in 
different 
educaEonal 
iniEaEves 
and 
JCP/AdoptJSR 
programs.
Stream 
API 
-­‐ An 
abstracEon 
that 
supports 
bulk 
operaEons 
over 
sequence 
of 
elements 
-­‐ Not 
a 
data 
structure 
-­‐ Simple 
and 
logical 
chaining 
of 
operaEons 
-­‐ Lazy 
evaluaEon 
-­‐ Internal 
parallelism 
if 
required 
-­‐ Concept 
of 
funcEonal 
programming 
in 
Java
txns.stream() 
Fluent 
and 
Simple 
.filter(t 
-­‐>t.getBuyer().getAge()>=65) 
.map(Txn::getSeller) 
.disEnct() 
.sort(comparing(Seller::getName)) 
.forEach(s 
-­‐> 
System.out.println(s.getName());
How 
can 
I 
get 
a 
Stream 
to 
work 
with? 
• CollecEon.stream() 
• IntStream.range() 
• Stream.of() 
• Arrays.stream() 
• BufferedReader.lines() 
• CharSequence.chars() 
• Pa`ern.splitAsStream()
Internal 
iteraEon 
over 
external 
Is 
there 
signifficant 
difference? 
for 
(Item 
item 
: 
items){ 
process(item); 
} 
items.forEach(item 
-­‐> 
process(item));
Lambda 
expressions 
A 
lambda 
expression 
is 
an 
anonymous 
funcEon 
– 
Has 
an 
argument 
list, 
a 
return 
type, 
and 
a 
body 
(Object 
o) 
-­‐> 
o.toString() 
– 
A 
method 
reference 
is 
a 
reference 
to 
an 
exisEng 
method 
Object::toString 
– 
Lambdas 
can 
refer 
to 
(capture) 
values 
from 
the 
enclosing 
lexical 
scope 
(Person 
p) 
-­‐>p.getName().equals(name) 
– 
Compiler 
can 
o:en 
infer 
argument 
types 
from 
context 
p 
-­‐> 
p.getName().equals(name) 
– 
Can 
be 
used 
whenever/wherever 
you 
use 
anonymous 
classes 
with 
single 
method 
You 
can 
now 
pass 
behavior 
as 
a 
data 
between 
your 
objects
Using 
lambdas 
FileFilter x = new FileFilter() { 
public boolean accept(File f) { 
return f.canRead(); 
} 
}; 
FileFilter x = (File f) -> f.canRead(); 
FileFilter x = File::canRead;
What’s 
your 
type? 
Since 
Java 
doesn’t 
have 
FuncEon 
type 
on 
it’s 
own 
Lambda’s 
type 
evaluated 
to 
some 
FuncEonal 
interface: 
Runnable 
r 
= 
() 
-­‐> 
{ 
doSmth(); 
}; 
Callable 
c 
= 
() 
-­‐> 
calcResult(); 
Comparator 
comp 
= 
(o1, 
o2) 
-­‐> 
compare(o1, 
o2);
FuncEonal 
interfaces 
java.u&l.func&on 
Package: 
Predicate<T> 
Determine 
if 
the 
input 
of 
type 
T 
matches 
some 
criteria 
Consumer<T> 
Accept 
a 
single 
input 
argumentof 
type 
T, 
and 
return 
no 
result 
Function<T, R> 
Apply 
a 
funcEon 
to 
the 
input 
type 
T, 
generaEng 
a 
result 
of 
type 
R 
java.u&l.stream 
Package: 
Collector<T, A, R> 
Used 
to 
collect 
stream 
of 
elements 
of 
type 
T 
into 
single 
result 
of 
type 
R 
Collectors 
Contains 
number 
of 
predefined 
Collectors
Influence 
on 
exisEng 
classes? 
java.lang.Iterable#forEach() 
java.uEl.CollecEon#stream() 
java.uEl.CollecEon#parallelStream() 
java.uEl.Comparator#comparing(…) 
java.uEl.Comparator#thenComparing(…) 
java.uEl.Comparator#reverse() 
…
InstrucEons 
• Download 
test 
project 
from 
GitHub: 
h`ps://github.com/olegts/LambdasHacking 
• Import 
it 
in 
your 
favorite 
IDE 
(IDEA*) 
with 
JDK8. 
• Open 
single 
Exercises 
class. 
• Fix 
as 
much 
tests 
as 
you 
can 
going 
one 
by 
one 
removing 
@Ignore 
annotaEon 
and 
coding 
up 
TODOs.
Thank 
you! 
Oleg 
Tsal-­‐Tsalko 
Email: 
oleg.tsalko@gmail.com 
Twi`er: 
@tsaltsol

Weitere ähnliche Inhalte

Was ist angesagt?

Reactive cocoa
Reactive cocoaReactive cocoa
Reactive cocoa
gillygize
 

Was ist angesagt? (20)

Java 8 presentation
Java 8 presentationJava 8 presentation
Java 8 presentation
 
Java 8 Lambda and Streams
Java 8 Lambda and StreamsJava 8 Lambda and Streams
Java 8 Lambda and Streams
 
Java8
Java8Java8
Java8
 
Java8 features
Java8 featuresJava8 features
Java8 features
 
Java 8
Java 8Java 8
Java 8
 
Streams in Java 8
Streams in Java 8Streams in Java 8
Streams in Java 8
 
Java 8 Intro - Core Features
Java 8 Intro - Core FeaturesJava 8 Intro - Core Features
Java 8 Intro - Core Features
 
Reactive cocoa
Reactive cocoaReactive cocoa
Reactive cocoa
 
Java 8 features
Java 8 featuresJava 8 features
Java 8 features
 
Java 8 Feature Preview
Java 8 Feature PreviewJava 8 Feature Preview
Java 8 Feature Preview
 
Java 8 Lambda Expressions & Streams
Java 8 Lambda Expressions & StreamsJava 8 Lambda Expressions & Streams
Java 8 Lambda Expressions & Streams
 
Java 8: the good parts!
Java 8: the good parts!Java 8: the good parts!
Java 8: the good parts!
 
Functions & closures
Functions & closuresFunctions & closures
Functions & closures
 
Introduction to Java 8
Introduction to Java 8Introduction to Java 8
Introduction to Java 8
 
Functional Java 8 in everyday life
Functional Java 8 in everyday lifeFunctional Java 8 in everyday life
Functional Java 8 in everyday life
 
Functional Programming in Java 8 - Exploiting Lambdas
Functional Programming in Java 8 - Exploiting LambdasFunctional Programming in Java 8 - Exploiting Lambdas
Functional Programming in Java 8 - Exploiting Lambdas
 
Scala in a nutshell by venkat
Scala in a nutshell by venkatScala in a nutshell by venkat
Scala in a nutshell by venkat
 
Lambdas and Laughs
Lambdas and LaughsLambdas and Laughs
Lambdas and Laughs
 
An Introduction to Reactive Cocoa
An Introduction to Reactive CocoaAn Introduction to Reactive Cocoa
An Introduction to Reactive Cocoa
 
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
 

Andere mochten auch

Andere mochten auch (10)

JUG involvment in JCP and AdopJSR program
JUG involvment in JCP and AdopJSR programJUG involvment in JCP and AdopJSR program
JUG involvment in JCP and AdopJSR program
 
Develop modern apps using Spring ecosystem at time of BigData
Develop modern apps using Spring ecosystem at time of BigData Develop modern apps using Spring ecosystem at time of BigData
Develop modern apps using Spring ecosystem at time of BigData
 
Next stop: Spring 4
Next stop: Spring 4Next stop: Spring 4
Next stop: Spring 4
 
Java 8 features
Java 8 featuresJava 8 features
Java 8 features
 
Java 8 date & time javaday2014
Java 8 date & time javaday2014Java 8 date & time javaday2014
Java 8 date & time javaday2014
 
Java 8 date & time
Java 8 date & timeJava 8 date & time
Java 8 date & time
 
Enterprise Integration Patterns
Enterprise Integration PatternsEnterprise Integration Patterns
Enterprise Integration Patterns
 
JUG UA AdoptJSR participation
JUG UA AdoptJSR participationJUG UA AdoptJSR participation
JUG UA AdoptJSR participation
 
Get ready for spring 4
Get ready for spring 4Get ready for spring 4
Get ready for spring 4
 
Distributed systems and scalability rules
Distributed systems and scalability rulesDistributed systems and scalability rules
Distributed systems and scalability rules
 

Ähnlich wie Lambdas HOL

FP in Java - Project Lambda and beyond
FP in Java - Project Lambda and beyondFP in Java - Project Lambda and beyond
FP in Java - Project Lambda and beyond
Mario Fusco
 
JDK8 : parallel programming made (too ?) easy
JDK8 : parallel programming made (too ?) easyJDK8 : parallel programming made (too ?) easy
JDK8 : parallel programming made (too ?) easy
José Paumard
 

Ähnlich wie Lambdas HOL (20)

Java 8 Workshop
Java 8 WorkshopJava 8 Workshop
Java 8 Workshop
 
Java8
Java8Java8
Java8
 
Xebicon2013 scala vsjava_final
Xebicon2013 scala vsjava_finalXebicon2013 scala vsjava_final
Xebicon2013 scala vsjava_final
 
New Features in JDK 8
New Features in JDK 8New Features in JDK 8
New Features in JDK 8
 
FP in Java - Project Lambda and beyond
FP in Java - Project Lambda and beyondFP in Java - Project Lambda and beyond
FP in Java - Project Lambda and beyond
 
JDK8 Lambdas and Streams: Changing The Way You Think When Developing Java
JDK8 Lambdas and Streams: Changing The Way You Think When Developing JavaJDK8 Lambdas and Streams: Changing The Way You Think When Developing Java
JDK8 Lambdas and Streams: Changing The Way You Think When Developing Java
 
Charles Sharp: Java 8 Streams
Charles Sharp: Java 8 StreamsCharles Sharp: Java 8 Streams
Charles Sharp: Java 8 Streams
 
Java gets a closure
Java gets a closureJava gets a closure
Java gets a closure
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009
 
New features in jdk8 iti
New features in jdk8 itiNew features in jdk8 iti
New features in jdk8 iti
 
Lambdas : Beyond The Basics
Lambdas : Beyond The BasicsLambdas : Beyond The Basics
Lambdas : Beyond The Basics
 
Thumbtack Expertise Days # 5 - Javaz
Thumbtack Expertise Days # 5 - JavazThumbtack Expertise Days # 5 - Javaz
Thumbtack Expertise Days # 5 - Javaz
 
Lambda Chops - Recipes for Simpler, More Expressive Code
Lambda Chops - Recipes for Simpler, More Expressive CodeLambda Chops - Recipes for Simpler, More Expressive Code
Lambda Chops - Recipes for Simpler, More Expressive Code
 
Protocol in Swift
Protocol in SwiftProtocol in Swift
Protocol in Swift
 
Java8: what's new and what's hot
Java8: what's new and what's hotJava8: what's new and what's hot
Java8: what's new and what's hot
 
JDK8 : parallel programming made (too ?) easy
JDK8 : parallel programming made (too ?) easyJDK8 : parallel programming made (too ?) easy
JDK8 : parallel programming made (too ?) easy
 
Java 8 Lambda Built-in Functional Interfaces
Java 8 Lambda Built-in Functional InterfacesJava 8 Lambda Built-in Functional Interfaces
Java 8 Lambda Built-in Functional Interfaces
 
java150929145120-lva1-app6892 (2).pptx
java150929145120-lva1-app6892 (2).pptxjava150929145120-lva1-app6892 (2).pptx
java150929145120-lva1-app6892 (2).pptx
 
Javaz. Functional design in Java 8.
Javaz. Functional design in Java 8.Javaz. Functional design in Java 8.
Javaz. Functional design in Java 8.
 
Introduction to clojure
Introduction to clojureIntroduction to clojure
Introduction to clojure
 

Kürzlich hochgeladen

AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
ankushspencer015
 

Kürzlich hochgeladen (20)

(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 
Glass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesGlass Ceramics: Processing and Properties
Glass Ceramics: Processing and Properties
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 

Lambdas HOL

  • 1. Lambdas HOL Speaker: Oleg Tsal-­‐Tsalko(@tsaltsol)
  • 2. About me Oleg Tsal-­‐Tsalko Lead So:ware Engineer at EPAM Systems. Speaker, acEve member of Kiev JUG. ParEcipate in different educaEonal iniEaEves and JCP/AdoptJSR programs.
  • 3. Stream API -­‐ An abstracEon that supports bulk operaEons over sequence of elements -­‐ Not a data structure -­‐ Simple and logical chaining of operaEons -­‐ Lazy evaluaEon -­‐ Internal parallelism if required -­‐ Concept of funcEonal programming in Java
  • 4. txns.stream() Fluent and Simple .filter(t -­‐>t.getBuyer().getAge()>=65) .map(Txn::getSeller) .disEnct() .sort(comparing(Seller::getName)) .forEach(s -­‐> System.out.println(s.getName());
  • 5. How can I get a Stream to work with? • CollecEon.stream() • IntStream.range() • Stream.of() • Arrays.stream() • BufferedReader.lines() • CharSequence.chars() • Pa`ern.splitAsStream()
  • 6. Internal iteraEon over external Is there signifficant difference? for (Item item : items){ process(item); } items.forEach(item -­‐> process(item));
  • 7. Lambda expressions A lambda expression is an anonymous funcEon – Has an argument list, a return type, and a body (Object o) -­‐> o.toString() – A method reference is a reference to an exisEng method Object::toString – Lambdas can refer to (capture) values from the enclosing lexical scope (Person p) -­‐>p.getName().equals(name) – Compiler can o:en infer argument types from context p -­‐> p.getName().equals(name) – Can be used whenever/wherever you use anonymous classes with single method You can now pass behavior as a data between your objects
  • 8. Using lambdas FileFilter x = new FileFilter() { public boolean accept(File f) { return f.canRead(); } }; FileFilter x = (File f) -> f.canRead(); FileFilter x = File::canRead;
  • 9. What’s your type? Since Java doesn’t have FuncEon type on it’s own Lambda’s type evaluated to some FuncEonal interface: Runnable r = () -­‐> { doSmth(); }; Callable c = () -­‐> calcResult(); Comparator comp = (o1, o2) -­‐> compare(o1, o2);
  • 10. FuncEonal interfaces java.u&l.func&on Package: Predicate<T> Determine if the input of type T matches some criteria Consumer<T> Accept a single input argumentof type T, and return no result Function<T, R> Apply a funcEon to the input type T, generaEng a result of type R java.u&l.stream Package: Collector<T, A, R> Used to collect stream of elements of type T into single result of type R Collectors Contains number of predefined Collectors
  • 11. Influence on exisEng classes? java.lang.Iterable#forEach() java.uEl.CollecEon#stream() java.uEl.CollecEon#parallelStream() java.uEl.Comparator#comparing(…) java.uEl.Comparator#thenComparing(…) java.uEl.Comparator#reverse() …
  • 12.
  • 13. InstrucEons • Download test project from GitHub: h`ps://github.com/olegts/LambdasHacking • Import it in your favorite IDE (IDEA*) with JDK8. • Open single Exercises class. • Fix as much tests as you can going one by one removing @Ignore annotaEon and coding up TODOs.
  • 14. Thank you! Oleg Tsal-­‐Tsalko Email: oleg.tsalko@gmail.com Twi`er: @tsaltsol