SlideShare a Scribd company logo
1 of 37
Download to read offline
Sayat Satybaldiyev 
Software Dev. @ Green Apple 
Twitter: Sayat_Stb 
Google Developers Group Almaty
Google Developers Group 
Almaty 
• Некоммерческое сообщество, в основе 
которого лежит обмен опытом и знаниями 
технологии Google для разработчиков - 
Android, Google Maps, App Engine, Chrome, 
Web Toolkit, Google Plus и другие. 
• Среди нас есть программисты, архитекторы, 
дизайнеры, IT-менеджеры, студенты и 
руководители. И мы всегда рады новым 
знакомствам :)
Спонсор фуршета 
•
История 
Lisp, Schema, Haskell
Как можно выбрать все зеленые яблоки из 
коллекции красных, желтых и зеленых 
яблок?
Functional vs Imperative 
List<Apple> result = new ArrayList<>(); 
for(Apple apple: input){ 
if(apple.getColor.equals("green")){ 
result.add(apple); 
} 
} 
return result;
Functional vs Imperative 
filterApples(input, 
(Apple a) -> { a.getColor().equals("green")} 
)
Принципы ФП 
• Higher Order Functions 
pass, create, return 
• Side Effects Free 
f(x, y) = x^2 + y ^2 
• Immutability 
easy to reason, multithreaded
Common FP operations 
map
Common FP operations 
filter
Common FP operations 
reduce
Java 8 Lambda Project 
The first ever big release since 1.5! 
aka Functional Style
First Lambdas 
button.addActionListener(new ActionListener() { 
public void actionPerformed(ActionEvent event) { 
System.out.println("button clicked") 
} 
});
First Lambdas 
button.addActionListener(new ActionListener() { 
public void actionPerformed(ActionEvent event) { 
System.out.println("button clicked") 
} 
}); 
button.addActionListener(event -> 
System.out.println("button clicked"));
Синтаксис Lambda 
Выражений 
• Lambda - anonymous function 
(arg1, arg2...) -> { body } 
(int x, int y) -> x + y 
(x, y) -> x + y 
() -> System.out.println(“Hello World”)
Functional Interface 
T => Boolean 
@FunctionalInterface 
public interface Predicate<T>{ 
boolean test(T t) 
} 
T => void 
@FunctionalInterface 
public interface Consumer<T>{ 
void accept(T t) 
} 
T => R 
@FunctionalInterface 
public interface Function<T, R>{ 
R apply(T t) 
} 
Def: A functional interface is an 
interface with a single abstract 
method that is used as the type 
of a lambda expression.
Functional Interface 
Represents a function that accepts one argument and produces a result. 
T => R 
@FunctionalInterface 
public interface Function<T, R>{ 
R apply(T t) 
} 
Function<Apple, String> = (Apple a ) -> a.toString()
Functional Interface 
Represents a predicate (boolean-valued function) of one argument. - 
Filter 
T => Boolean 
@FunctionalInterface 
public interface Predicate<T>{ 
boolean test(T t) 
} 
Predicate<Integer> atLeast5 = ( x ) -> x > 5;
Functional Interface 
Represents an operation that accepts a single input argument and returns no 
result. 
T => void 
@FunctionalInterface 
public interface Consumer<T>{ 
void accept(T t) 
} 
Consumer<Apple> = (Apple a) -> System.out.println(a.toString())
Stream APIs
Streams 
• No Storage 
• Lazy Evaluations 
• Infinite/Finite Stream 
• Single Usage 
• Ordered/Unordered 
• Parallel/Sequential
Streams 
Declarative Style 
what to do NOT how 
List<String> myList = Arrays.asList("a1", "a2", "b1", "c2", "c1"); 
myList 
.stream() 
.filter(s -> s.startsWith("c")) 
.map(String::toUpperCase) 
.sorted() 
.forEach(System.out::println);
Streams 
Pipes-and-filter Style API
Creating Stream API 
Arrays.stream() 
Stream<Integer> = Stream.of(1, 2, 3) 
Infinite 
Stream.iterate(0, n-> n + 10) 
ex: with limit - fixed size
Stream Operatons 
filter(Predicate<T>) 
map(Function<R, T>) 
sorted(Comparator<T>) 
limit(long maxSize) 
distinct()
Terminal Stream Operation 
Terminal 
sum() 
max()/min() 
average() 
forEach() 
collect()
Parallel Stream
Количество зеленых яблок в колекции? 
int count = 0; 
for (Apple apple : allApples) { 
if (apple.equals("green")) { 
count++; 
} } 
return count;
Количество зеленых яблок в колекции? 
int count = 0; 
Iterator<Apple> iterator = allApples.iterator(); 
while(iterator.hasNext()) { 
Apple apple = iterator.next(); 
if (apple.equals("green")) { 
count++; } 
}
Parallel Streams 
public int parallelArraySum() { 
return albums.parallelStream() 
.mapToInt((Track tr) -> tr.getLength) 
.sum(); 
} 
● Fork and Join Framework 
● NOT keep order of stream
Performance 
private int addIntegers(List<Integer> values) { 
return values.parallelStream() 
.mapToInt(i -> i) 
.sum(); 
}
Performance
Performance 
Data size 
Source data structure 
# cores
FP in Java 8 
1. FP(ish) programming 
2. Declarative 
3. Working with Data Processing
Спасибо за внимание 
www.GDGalmaty.org 
Google Developers Group Almaty
Optional

More Related Content

What's hot

Hive function-cheat-sheet
Hive function-cheat-sheetHive function-cheat-sheet
Hive function-cheat-sheetDr. Volkan OBAN
 
Building a Tagless Final DSL for WebGL
Building a Tagless Final DSL for WebGLBuilding a Tagless Final DSL for WebGL
Building a Tagless Final DSL for WebGLLuka Jacobowitz
 
The Ring programming language version 1.5.2 book - Part 21 of 181
The Ring programming language version 1.5.2 book - Part 21 of 181The Ring programming language version 1.5.2 book - Part 21 of 181
The Ring programming language version 1.5.2 book - Part 21 of 181Mahmoud Samir Fayed
 
Rewriting Java In Scala
Rewriting Java In ScalaRewriting Java In Scala
Rewriting Java In ScalaSkills Matter
 
Principled Error Handling with FP
Principled Error Handling with FPPrincipled Error Handling with FP
Principled Error Handling with FPLuka Jacobowitz
 
Java 8 Stream API. A different way to process collections.
Java 8 Stream API. A different way to process collections.Java 8 Stream API. A different way to process collections.
Java 8 Stream API. A different way to process collections.David Gómez García
 
Collections In Scala
Collections In ScalaCollections In Scala
Collections In ScalaKnoldus Inc.
 
Functional Programming in Javascript - IL Tech Talks week
Functional Programming in Javascript - IL Tech Talks weekFunctional Programming in Javascript - IL Tech Talks week
Functional Programming in Javascript - IL Tech Talks weekyoavrubin
 
Functional Programming with JavaScript
Functional Programming with JavaScriptFunctional Programming with JavaScript
Functional Programming with JavaScriptWebF
 
Data structure lab manual
Data structure lab manualData structure lab manual
Data structure lab manualnikshaikh786
 
Engineering lecture ppt by venay magen
Engineering lecture ppt by venay magenEngineering lecture ppt by venay magen
Engineering lecture ppt by venay magenvenaymagen19
 
Functor, Apply, Applicative And Monad
Functor, Apply, Applicative And MonadFunctor, Apply, Applicative And Monad
Functor, Apply, Applicative And MonadOliver Daff
 
The Ring programming language version 1.2 book - Part 21 of 84
The Ring programming language version 1.2 book - Part 21 of 84The Ring programming language version 1.2 book - Part 21 of 84
The Ring programming language version 1.2 book - Part 21 of 84Mahmoud Samir Fayed
 
simple linear regression
simple linear regressionsimple linear regression
simple linear regressionAkhilesh Joshi
 
Side by Side - Scala and Java Adaptations of Martin Fowler’s Javascript Refac...
Side by Side - Scala and Java Adaptations of Martin Fowler’s Javascript Refac...Side by Side - Scala and Java Adaptations of Martin Fowler’s Javascript Refac...
Side by Side - Scala and Java Adaptations of Martin Fowler’s Javascript Refac...Philip Schwarz
 

What's hot (19)

Hive function-cheat-sheet
Hive function-cheat-sheetHive function-cheat-sheet
Hive function-cheat-sheet
 
Building a Tagless Final DSL for WebGL
Building a Tagless Final DSL for WebGLBuilding a Tagless Final DSL for WebGL
Building a Tagless Final DSL for WebGL
 
The Ring programming language version 1.5.2 book - Part 21 of 181
The Ring programming language version 1.5.2 book - Part 21 of 181The Ring programming language version 1.5.2 book - Part 21 of 181
The Ring programming language version 1.5.2 book - Part 21 of 181
 
Java8
Java8Java8
Java8
 
Rewriting Java In Scala
Rewriting Java In ScalaRewriting Java In Scala
Rewriting Java In Scala
 
Principled Error Handling with FP
Principled Error Handling with FPPrincipled Error Handling with FP
Principled Error Handling with FP
 
Java 8 Stream API. A different way to process collections.
Java 8 Stream API. A different way to process collections.Java 8 Stream API. A different way to process collections.
Java 8 Stream API. A different way to process collections.
 
Collections In Scala
Collections In ScalaCollections In Scala
Collections In Scala
 
Functional Programming in Javascript - IL Tech Talks week
Functional Programming in Javascript - IL Tech Talks weekFunctional Programming in Javascript - IL Tech Talks week
Functional Programming in Javascript - IL Tech Talks week
 
Functional Programming with JavaScript
Functional Programming with JavaScriptFunctional Programming with JavaScript
Functional Programming with JavaScript
 
R-Shiny Cheat sheet
R-Shiny Cheat sheetR-Shiny Cheat sheet
R-Shiny Cheat sheet
 
Data structure lab manual
Data structure lab manualData structure lab manual
Data structure lab manual
 
Python programming : Arrays
Python programming : ArraysPython programming : Arrays
Python programming : Arrays
 
Engineering lecture ppt by venay magen
Engineering lecture ppt by venay magenEngineering lecture ppt by venay magen
Engineering lecture ppt by venay magen
 
Functor, Apply, Applicative And Monad
Functor, Apply, Applicative And MonadFunctor, Apply, Applicative And Monad
Functor, Apply, Applicative And Monad
 
The Ring programming language version 1.2 book - Part 21 of 84
The Ring programming language version 1.2 book - Part 21 of 84The Ring programming language version 1.2 book - Part 21 of 84
The Ring programming language version 1.2 book - Part 21 of 84
 
simple linear regression
simple linear regressionsimple linear regression
simple linear regression
 
Side by Side - Scala and Java Adaptations of Martin Fowler’s Javascript Refac...
Side by Side - Scala and Java Adaptations of Martin Fowler’s Javascript Refac...Side by Side - Scala and Java Adaptations of Martin Fowler’s Javascript Refac...
Side by Side - Scala and Java Adaptations of Martin Fowler’s Javascript Refac...
 
Scala collection
Scala collectionScala collection
Scala collection
 

Viewers also liked

Пути обхода граблей в стартапах. GDG Almaty
Пути обхода граблей в стартапах. GDG AlmatyПути обхода граблей в стартапах. GDG Almaty
Пути обхода граблей в стартапах. GDG AlmatyMadina Kamzina
 
Nigeria state of digital media
Nigeria  state of digital mediaNigeria  state of digital media
Nigeria state of digital mediaElo Umeh
 
Audience feedback statistics
Audience feedback statisticsAudience feedback statistics
Audience feedback statisticsgabbi_abi
 
10 Gebote zur Fotografie
10 Gebote zur Fotografie10 Gebote zur Fotografie
10 Gebote zur FotografieChristina_l_m
 
Lean start up & innovation
Lean start up & innovationLean start up & innovation
Lean start up & innovationElo Umeh
 

Viewers also liked (6)

Пути обхода граблей в стартапах. GDG Almaty
Пути обхода граблей в стартапах. GDG AlmatyПути обхода граблей в стартапах. GDG Almaty
Пути обхода граблей в стартапах. GDG Almaty
 
Nigeria state of digital media
Nigeria  state of digital mediaNigeria  state of digital media
Nigeria state of digital media
 
PG & Associates
PG & AssociatesPG & Associates
PG & Associates
 
Audience feedback statistics
Audience feedback statisticsAudience feedback statistics
Audience feedback statistics
 
10 Gebote zur Fotografie
10 Gebote zur Fotografie10 Gebote zur Fotografie
10 Gebote zur Fotografie
 
Lean start up & innovation
Lean start up & innovationLean start up & innovation
Lean start up & innovation
 

Similar to Gdg almaty. Функциональное программирование в Java 8

New Functional Features of Java 8
New Functional Features of Java 8New Functional Features of Java 8
New Functional Features of Java 8franciscoortin
 
Functional aspects of java 8
Functional aspects of java 8Functional aspects of java 8
Functional aspects of java 8Jobaer Chowdhury
 
Introduction to Java 8
Introduction to Java 8Introduction to Java 8
Introduction to Java 8Knoldus Inc.
 
Real Time Big Data Management
Real Time Big Data ManagementReal Time Big Data Management
Real Time Big Data ManagementAlbert Bifet
 
Java 8: more readable and flexible code
Java 8: more readable and flexible codeJava 8: more readable and flexible code
Java 8: more readable and flexible codeWeAreEsynergy
 
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 Built-in Functional Interfaces
Java 8 Lambda Built-in Functional InterfacesJava 8 Lambda Built-in Functional Interfaces
Java 8 Lambda Built-in Functional InterfacesGanesh Samarthyam
 
Flink Forward San Francisco 2019: Build a Table-centric Apache Flink Ecosyste...
Flink Forward San Francisco 2019: Build a Table-centric Apache Flink Ecosyste...Flink Forward San Francisco 2019: Build a Table-centric Apache Flink Ecosyste...
Flink Forward San Francisco 2019: Build a Table-centric Apache Flink Ecosyste...Flink Forward
 
Flink Forward San Francisco 2019: Build a Table-centric Apache Flink Ecosyste...
Flink Forward San Francisco 2019: Build a Table-centric Apache Flink Ecosyste...Flink Forward San Francisco 2019: Build a Table-centric Apache Flink Ecosyste...
Flink Forward San Francisco 2019: Build a Table-centric Apache Flink Ecosyste...Flink Forward
 
New Features in JDK 8
New Features in JDK 8New Features in JDK 8
New Features in JDK 8Martin Toshev
 

Similar to Gdg almaty. Функциональное программирование в Java 8 (20)

Fp java8
Fp java8Fp java8
Fp java8
 
New Functional Features of Java 8
New Functional Features of Java 8New Functional Features of Java 8
New Functional Features of Java 8
 
Java 8 new features
Java 8 new featuresJava 8 new features
Java 8 new features
 
Functional aspects of java 8
Functional aspects of java 8Functional aspects of java 8
Functional aspects of java 8
 
Monads in Swift
Monads in SwiftMonads in Swift
Monads in Swift
 
Introduction to Java 8
Introduction to Java 8Introduction to Java 8
Introduction to Java 8
 
Java 8
Java 8Java 8
Java 8
 
Lambda Functions in Java 8
Lambda Functions in Java 8Lambda Functions in Java 8
Lambda Functions in Java 8
 
Java 8 Workshop
Java 8 WorkshopJava 8 Workshop
Java 8 Workshop
 
Real Time Big Data Management
Real Time Big Data ManagementReal Time Big Data Management
Real Time Big Data Management
 
Java 8: more readable and flexible code
Java 8: more readable and flexible codeJava 8: more readable and flexible code
Java 8: more readable and flexible code
 
Pune Clojure Course Outline
Pune Clojure Course OutlinePune Clojure Course Outline
Pune Clojure Course Outline
 
Java 8 Stream API (Valdas Zigas)
Java 8 Stream API (Valdas Zigas)Java 8 Stream API (Valdas Zigas)
Java 8 Stream API (Valdas Zigas)
 
Java 8 Intro - Core Features
Java 8 Intro - Core FeaturesJava 8 Intro - Core Features
Java 8 Intro - Core Features
 
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 Built-in Functional Interfaces
Java 8 Lambda Built-in Functional InterfacesJava 8 Lambda Built-in Functional Interfaces
Java 8 Lambda Built-in Functional Interfaces
 
Functional Programming
Functional ProgrammingFunctional Programming
Functional Programming
 
Flink Forward San Francisco 2019: Build a Table-centric Apache Flink Ecosyste...
Flink Forward San Francisco 2019: Build a Table-centric Apache Flink Ecosyste...Flink Forward San Francisco 2019: Build a Table-centric Apache Flink Ecosyste...
Flink Forward San Francisco 2019: Build a Table-centric Apache Flink Ecosyste...
 
Flink Forward San Francisco 2019: Build a Table-centric Apache Flink Ecosyste...
Flink Forward San Francisco 2019: Build a Table-centric Apache Flink Ecosyste...Flink Forward San Francisco 2019: Build a Table-centric Apache Flink Ecosyste...
Flink Forward San Francisco 2019: Build a Table-centric Apache Flink Ecosyste...
 
New Features in JDK 8
New Features in JDK 8New Features in JDK 8
New Features in JDK 8
 

Recently uploaded

Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptxPoojaSen20
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 

Recently uploaded (20)

Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 

Gdg almaty. Функциональное программирование в Java 8

  • 1. Sayat Satybaldiyev Software Dev. @ Green Apple Twitter: Sayat_Stb Google Developers Group Almaty
  • 2. Google Developers Group Almaty • Некоммерческое сообщество, в основе которого лежит обмен опытом и знаниями технологии Google для разработчиков - Android, Google Maps, App Engine, Chrome, Web Toolkit, Google Plus и другие. • Среди нас есть программисты, архитекторы, дизайнеры, IT-менеджеры, студенты и руководители. И мы всегда рады новым знакомствам :)
  • 4.
  • 6. Как можно выбрать все зеленые яблоки из коллекции красных, желтых и зеленых яблок?
  • 7. Functional vs Imperative List<Apple> result = new ArrayList<>(); for(Apple apple: input){ if(apple.getColor.equals("green")){ result.add(apple); } } return result;
  • 8. Functional vs Imperative filterApples(input, (Apple a) -> { a.getColor().equals("green")} )
  • 9. Принципы ФП • Higher Order Functions pass, create, return • Side Effects Free f(x, y) = x^2 + y ^2 • Immutability easy to reason, multithreaded
  • 13. Java 8 Lambda Project The first ever big release since 1.5! aka Functional Style
  • 14. First Lambdas button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { System.out.println("button clicked") } });
  • 15. First Lambdas button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { System.out.println("button clicked") } }); button.addActionListener(event -> System.out.println("button clicked"));
  • 16. Синтаксис Lambda Выражений • Lambda - anonymous function (arg1, arg2...) -> { body } (int x, int y) -> x + y (x, y) -> x + y () -> System.out.println(“Hello World”)
  • 17. Functional Interface T => Boolean @FunctionalInterface public interface Predicate<T>{ boolean test(T t) } T => void @FunctionalInterface public interface Consumer<T>{ void accept(T t) } T => R @FunctionalInterface public interface Function<T, R>{ R apply(T t) } Def: A functional interface is an interface with a single abstract method that is used as the type of a lambda expression.
  • 18. Functional Interface Represents a function that accepts one argument and produces a result. T => R @FunctionalInterface public interface Function<T, R>{ R apply(T t) } Function<Apple, String> = (Apple a ) -> a.toString()
  • 19. Functional Interface Represents a predicate (boolean-valued function) of one argument. - Filter T => Boolean @FunctionalInterface public interface Predicate<T>{ boolean test(T t) } Predicate<Integer> atLeast5 = ( x ) -> x > 5;
  • 20. Functional Interface Represents an operation that accepts a single input argument and returns no result. T => void @FunctionalInterface public interface Consumer<T>{ void accept(T t) } Consumer<Apple> = (Apple a) -> System.out.println(a.toString())
  • 22. Streams • No Storage • Lazy Evaluations • Infinite/Finite Stream • Single Usage • Ordered/Unordered • Parallel/Sequential
  • 23. Streams Declarative Style what to do NOT how List<String> myList = Arrays.asList("a1", "a2", "b1", "c2", "c1"); myList .stream() .filter(s -> s.startsWith("c")) .map(String::toUpperCase) .sorted() .forEach(System.out::println);
  • 25. Creating Stream API Arrays.stream() Stream<Integer> = Stream.of(1, 2, 3) Infinite Stream.iterate(0, n-> n + 10) ex: with limit - fixed size
  • 26. Stream Operatons filter(Predicate<T>) map(Function<R, T>) sorted(Comparator<T>) limit(long maxSize) distinct()
  • 27. Terminal Stream Operation Terminal sum() max()/min() average() forEach() collect()
  • 29. Количество зеленых яблок в колекции? int count = 0; for (Apple apple : allApples) { if (apple.equals("green")) { count++; } } return count;
  • 30. Количество зеленых яблок в колекции? int count = 0; Iterator<Apple> iterator = allApples.iterator(); while(iterator.hasNext()) { Apple apple = iterator.next(); if (apple.equals("green")) { count++; } }
  • 31. Parallel Streams public int parallelArraySum() { return albums.parallelStream() .mapToInt((Track tr) -> tr.getLength) .sum(); } ● Fork and Join Framework ● NOT keep order of stream
  • 32. Performance private int addIntegers(List<Integer> values) { return values.parallelStream() .mapToInt(i -> i) .sum(); }
  • 34. Performance Data size Source data structure # cores
  • 35. FP in Java 8 1. FP(ish) programming 2. Declarative 3. Working with Data Processing
  • 36. Спасибо за внимание www.GDGalmaty.org Google Developers Group Almaty