SlideShare a Scribd company logo
F U N C T I O N A L - R E A C T I V E
@ S V E N R U P P E R T
5
S T O R Y A N D P H I L O S O P H Y
Software is eating the world and what most of us see of it is the user interface. The user
interface has become the key component of how the users experience the business
behind it. Competition is lost or won due to user experience. Simplicity is king and the
users get frustrated by anything ugly, slow or not working on the device they happen to
use at the time. We at Vaadin fight for simplicity and invite everyone to join this fight.
Together we want to build a user interface that puts a smile on the user’s face.
Vaadin is the technology that empowers developers to build the best web-apps for
business purposes. Our priority over everything else is developer productivity because
we believe that by simplifying the developer experience and saving the developer’s
time, they are best able to focus on building great user interfaces.
Our brand is what we want everyone to think about us. When everyone - both us and
the people around us - have a consistent understanding of what Vaadin is and what we
stand for, it enables that image to spread and amplify. This book defines what we want
that image to be. It defines what the Vaadin brand is.
I hope that You are as excited and proud of living and breathing the Vaadin brand as
I am. You are the one who is shaping what everyone thinks about Vaadin - using this
brand as a tool and a guideline every day.
Let’s fight for simplicity for both the users and the developers!
Joonas Lehtinen
Founder & CEO
Vaadin
I N T R O D U C T I O N
W I T H C O R E J AVA 8 - 11 A N D B E Y O N D
S V E N R U P P E R T 

Developer Advocate @ Vaadin
5
C O D I N G J AVA S I N C E 1 9 9 6
C O N S U LT I N G W O R L D W I D E
Public Sector: Military / Government
Private Sector: Automotive / Aerospace / SMB /
NonProfit / NonGov: World Bank / UN / YPARD / CGIAR
D I S T R I B U T E D S Y S T E M S S I N C E 2 0 0 2
J O I N E D VA A D I N 2 0 1 7
I N T R O
D I F F E R E N C E S B E T W E E N O O A N D F P I N J AVA
4
@SvenRuppertJava8 - Optional<T>
the border between OO and FP in Java is not 100% clear.
@SvenRuppert
S I N C E J AVA 8
Functional Interfaces - basics
6
@SvenRuppertJava8 - Functional Interfaces
7
@SvenRuppertJava8 - Functional Interfaces
8
@SvenRuppertJava8 - Functional Interfaces
9
@SvenRuppertJava8 - Functional Interfaces
10
@SvenRuppertJava9 - Functional Interfaces
Java9 - JEP213
@SvenRuppert
E X E R C I S E S
S I N C E J AVA 8
Functional Interfaces - basics
@SvenRuppert
S I N C E J AVA 8
Optional<T>
Optional<T> @SvenRuppert
Optional<T> @SvenRuppert
Optional<T> @SvenRuppert
Optional<T> - since JDK10 @SvenRuppert
@SvenRuppert
E X E R C I S E S
S I N C E J AVA 8
Optional<T>
@SvenRuppert
S I N C E J AVA 8
Result<T>
Optional<T> @SvenRuppert
Not symmetric
Not async - blocking only
Not functional enough
Declared final - no inheritance Having ValueTypes in mind
We need something
Result<T> @SvenRuppert
Must be easy to transform Optional <-> Result
Should work as an Drop-In-Replacement
Should connect to the Reactive-World
Should be symmetric
Must fit functional style / oo style
Result<T> @SvenRuppert
Transform from and to an Optional
pos. and neg. available
@SvenRuppert
Symmetric
Handle both ways
Result<T>
@SvenRuppert
Handle both ways
Async if needed
Result<T>
@SvenRuppert
Combine with Value and Transformation
Async if needed
Result<T>
@SvenRuppert
Combine with Value / Function
Async if needed
Combine with a function
Result<T>
@SvenRuppert
E X E R C I S E S
S I N C E J AVA 8
Result<T>
@SvenRuppert
S I N C E J AVA 8
Exceptions
Exceptions @SvenRuppert
Exceptions @SvenRuppert
Exceptions @SvenRuppert
Exceptions @SvenRuppert
JDK9
Exceptions @SvenRuppert
Exceptions @SvenRuppert
Exceptions @SvenRuppert
Exceptions @SvenRuppert
Exceptions @SvenRuppert
Exceptions @SvenRuppert
Exceptions @SvenRuppert
different exceptions
@SvenRuppert
E X E R C I S E S
S I N C E J AVA 8
Exceptions
@SvenRuppert
H O W T O U S E F U N C T I O N S …
Functions - Basics
Functions - Java8
41
@SvenRuppert
a function is a transformation
input -> output
(input - type, input value) (output - type, output value)
Functions - Java8
42
@SvenRuppert
43
@SvenRuppertFunctions - Java8
44
@SvenRuppertFunctions - Java8
45
@SvenRuppertFunctions - Java8
46
@SvenRuppert
Compose is not so nice.. but
Functions - Java8
47
@SvenRuppert
Attention : make a semantic equal function !!
Functions - Java8
48
@SvenRuppertFunctions - Java8
How to get an instance of a function?
49
@SvenRuppertFunctions - Java8
50
@SvenRuppertFunctions - Java8
51
@SvenRuppertFunctions - Java8
Functions - Java8 - extract the logic !
52
@SvenRuppert
53
@SvenRuppertFunctions - Java8
54
@SvenRuppertFunctions - Java8
@SvenRuppert
E X E R C I S E S
H O W T O U S E F U N C T I O N S …
Functions - Basics
@SvenRuppert
G E N E R I C B A C K A N D F O R WA R D
Currying
Currying @SvenRuppert
@SvenRuppertCurrying
@SvenRuppertCurrying
@SvenRuppertCurrying
@SvenRuppert
E X E R C I S E S
G E N E R I C B A C K A N D F O R WA R D
Currying
@SvenRuppert
P U R E F U N C T I O N A L B E H AV I O R
Memoizing
Memoizing @SvenRuppert
Memoizing @SvenRuppert
Memoizing @SvenRuppert
Memoizing @SvenRuppert
Memoizing @SvenRuppert
Memoizing @SvenRuppert
Memoizing @SvenRuppert
Memoizing @SvenRuppert
Memoizing @SvenRuppert
Memoizing @SvenRuppert
Memoizing @SvenRuppert
@SvenRuppert
E X E R C I S E S
P U R E F U N C T I O N A L B E H AV I O R
Memoizing
@SvenRuppert
H O W T O D E C I D E ?
Case
Case @SvenRuppert
@SvenRuppertCase
@SvenRuppertCase
@SvenRuppertCase
@SvenRuppertCase
@SvenRuppert
E X E R C I S E S
H O W T O D E C I D E ?
Case
@SvenRuppert
H O W T O U S E , H O W T O B U I L D
Streams
Streams @SvenRuppert
Streams @SvenRuppert
A Stream is active after creation
want to define a Stream without starting it
maybe creating it interactively
we need a function !
Function<T, Stream<R>>
@SvenRuppert
E X E R C I S E S
H O W T O U S E , H O W T O B U I L D
Streams
Refactoring example
based on Java8
@SvenRuppert
86
@SvenRuppertJava8 - Functional Interfaces - Example
typical legacy implementation
87
@SvenRuppertJava8 - Functional Interfaces - Example
typical legacy implementation
88
@SvenRuppertJava8 - Functional Interfaces - Example
89
@SvenRuppertJava8 - Functional Interfaces - Example
90
@SvenRuppertJava8 - Functional Interfaces - Example
91
@SvenRuppertJava8 - Functional Interfaces - Example
92
@SvenRuppertJava8 - Functional Interfaces - Example
93
@SvenRuppertJava8 - Functional Interfaces - Example
Sourcecode is on github
Pattern in Java 8/9
how pattern will change…
@SvenRuppert
Virtual Proxy
94
@SvenRuppert
Virtual Proxy
95
@SvenRuppert
public class ServiceProxy implements Service {

private Service service = new ServiceImpl();

public String work(String txt) { return service.work(txt); }

}
What could we
change now ? Virtual Proxy:
create the Delegator later
public class VirtualService implements Service {

private Service service = null;

public String work(String txt) {

if(service == null) { service = new ServiceImpl(); }

return service.work(txt);

}

}
Virtual Proxy
96
@SvenRuppert
public class VirtualService implements Service {

private Service service = null;

public String work(String txt) {

if(service == null) { service = new ServiceImpl(); }


return service.work(txt);

}

}
This is NOT ThreadSafe
fixed decision for
an implementation
how to combine it with
a FactoryPattern ?
Virtual Proxy
97
@SvenRuppert
if(service == null) { service = new ServiceImpl(); }

public interface ServiceFactory {

Service createInstance();

}
public interface ServiceStrategyFactory {

Service realSubject(ServiceFactory factory);

}
Virtual Proxy - Not - ThreadSafe
98
@SvenRuppert
if(service == null) { service = new ServiceImpl(); }

public class ServiceStrategyFactoryImpl implements ServiceStrategyFactory {

Service realSubject;

public Service realSubject(final ServiceFactory factory) {

if (realSubject == null) {

realSubject = factory.createInstance();

}

return realSubject;

}

}
private ServiceFactory serviceFactory = ServiceImpl::new;
Virtual Proxy - Not - ThreadSafe
99
@SvenRuppert
if(service == null) { service = new ServiceImpl(); }

public class ServiceProxy implements Service {
private ServiceFactory serviceFactory = ServiceImpl::new;
private ServiceStrategyFactory strategyFactory = new ServiceStrategyFactoryImpl();
public String work(String txt) {
return strategyFactory .realSubject(serviceFactory).work(txt);
}

}
Virtual Proxy - Show some code….
100
@SvenRuppert
Virtual Proxy - Show some code….
101
@SvenRuppert
Virtual Proxy - Show some code….
102
@SvenRuppert
Virtual Proxy - Show some code….
103
@SvenRuppert
Virtual Proxy - Show some code….
104
@SvenRuppert
Virtual Proxy - Show some code….
105
@SvenRuppert
Virtual Proxy - Show some code….
106
@SvenRuppert
Virtual Proxy - Show some code….
107
@SvenRuppert
Virtual Proxy - Show some code….
108
@SvenRuppert
Virtual Proxy - Show some code….
109
@SvenRuppert
Decorator - pre Java8
110
@SvenRuppert
Decorator - pre Java8
111
@SvenRuppert
Decorator - pre Java8
112
@SvenRuppert
Decorator - pre Java8
113
@SvenRuppert
Decorator - Java8
114
@SvenRuppert
Decorator - Java8
115
@SvenRuppert
Decorator - Java8
116
@SvenRuppert
Decorator - Java8 - modify orig Interface
117
@SvenRuppert
Decorator - Java8 - DoubleUnaryOperator
118
@SvenRuppert
Interpreter - pre Java8
119
@SvenRuppert
Interpreter - pre Java8
120
@SvenRuppert
Interpreter - pre Java8
121
@SvenRuppert
Interpreter - pre Java8
122
@SvenRuppert
Interpreter - Java8 - Java9
123
@SvenRuppert
Interpreter - Java8 - Java9
124
@SvenRuppert
Main Idea - DataStructure to Function
Interpreter - Java8 - Java9
125
@SvenRuppert
@SvenRuppert
H O W R E A C T I V E W I L L S TA R T
Observer
127
@SvenRuppertObserver
128
@SvenRuppertObserver
129
@SvenRuppertObserver
130
@SvenRuppertObserver
key not needed anymore
131
@SvenRuppertObserver
132
@SvenRuppertObserver H O W T O C H A I N O B S E R V E R ?
@SvenRuppert
E X E R C I S E S
H O W R E A C T I V E W I L L S TA R T
Observer
@SvenRuppert
H O W T O U S E F U N C T I O N S … A S Y N C …
CompletableFuture
135
@SvenRuppertJava8 - CompletableFuture
Process
Thread
Fiber
CompletionStage CompletionStage CompletionStage
136
@SvenRuppertJava8 - CompletableFuture
137
@SvenRuppertJava8 - CompletableFuture
138
@SvenRuppert
Operator 1
Value A
Operator 2a
Result
Value B Value C
Java8 - CompletableFuture
139
@SvenRuppertJava8 - CompletableFuture
140
@SvenRuppertJava8 - CompletableFuture
141
@SvenRuppertJava8 - CompletableFuture
142
@SvenRuppertJava8 - CompletableFuture
Operator 1
Value A
Operator 2a
Result
Value B Value C
@SvenRuppert
E X E R C I S E S
H O W T O U S E F U N C T I O N S … A S Y N C …
CompletableFuture
@SvenRuppert
H O W T O C R E AT E A G R A P H E A S Y. .
CompletableFutureQueue
145
@SvenRuppertCompletableFutureQueue
CompletableFuture is active after creation
want to define a CompletableFuture without starting it
maybe creating it interactively
we need a function !
Function<T, CompletableFuture<R>>
146
@SvenRuppertCompletableFutureQueue
147
@SvenRuppertCompletableFutureQueue
@SvenRuppert
E X E R C I S E S
H O W T O C R E AT E A G R A P H E A S Y. .
CompletableFutureQueue
Java 9
some nice news…
@SvenRuppert
Java9 - Optional
149
@SvenRuppert
Java9 - JEP266
150
@SvenRuppert
we got Publisher / Subscriber
@SvenRuppert
I N T E R FA C E O R I M P L E M E N TAT I O N ?
Var
@SvenRuppert
E X E R C I S E S
I N T E R FA C E O R I M P L E M E N TAT I O N ?
Var
Summary
X
@SvenRuppert
places to read more about it
www.functional-reactive.org
https://github.com/functional-reactive
Summary
153
@SvenRuppert
please, follow me ;-)
@SvenRuppert
Thank You !!!

More Related Content

Similar to Functional Reactive with Core Java - Workshop - Slides (20)

PPTX
SoCal Code Camp 2015: An introduction to Java 8
Chaitanya Ganoo
 
PDF
SeneJug java_8_prez_122015
senejug
 
PDF
Software Frameworks
adil raja
 
PPTX
A brief tour of modern Java
Sina Madani
 
PPTX
Functional programming
Lhouceine OUHAMZA
 
PPTX
Software Uni Conf October 2014
Nayden Gochev
 
PDF
From desktop to the cloud, cutting costs with Virtual kubelet and ACI
Adi Polak
 
PDF
Functional Programming In Java Harnessing The Power Of Java 8 Lambda Expressi...
coriehokitiw
 
PDF
Functional Programming In Java Harnessing The Power Of Java 8 Lambda Expressi...
coriehokitiw
 
PDF
Java 8 - functional features
Rafal Rybacki
 
PDF
Non-functional requirements
Rohela Raouf
 
PPTX
Java 8
vpulec
 
PPTX
Lambdas : Beyond The Basics
Simon Ritter
 
PDF
Fun with java 8
Victor Perepelitsky
 
PPTX
What's New in Java 8
javafxpert
 
PDF
Question 1 Some agile and incremental methods- like extreme programmi.pdf
PhilzIGHudsonl
 
PDF
Java 8 Interview Questions and Answers PDF By ScholarHat.pdf
Scholarhat
 
PPTX
Functional Leap of Faith (Keynote at JDay Lviv 2014)
Tomer Gabel
 
PPTX
Intro to java 8
John Godoi
 
PPT
Bdd with m spec
Pavneet Singh Saund
 
SoCal Code Camp 2015: An introduction to Java 8
Chaitanya Ganoo
 
SeneJug java_8_prez_122015
senejug
 
Software Frameworks
adil raja
 
A brief tour of modern Java
Sina Madani
 
Functional programming
Lhouceine OUHAMZA
 
Software Uni Conf October 2014
Nayden Gochev
 
From desktop to the cloud, cutting costs with Virtual kubelet and ACI
Adi Polak
 
Functional Programming In Java Harnessing The Power Of Java 8 Lambda Expressi...
coriehokitiw
 
Functional Programming In Java Harnessing The Power Of Java 8 Lambda Expressi...
coriehokitiw
 
Java 8 - functional features
Rafal Rybacki
 
Non-functional requirements
Rohela Raouf
 
Java 8
vpulec
 
Lambdas : Beyond The Basics
Simon Ritter
 
Fun with java 8
Victor Perepelitsky
 
What's New in Java 8
javafxpert
 
Question 1 Some agile and incremental methods- like extreme programmi.pdf
PhilzIGHudsonl
 
Java 8 Interview Questions and Answers PDF By ScholarHat.pdf
Scholarhat
 
Functional Leap of Faith (Keynote at JDay Lviv 2014)
Tomer Gabel
 
Intro to java 8
John Godoi
 
Bdd with m spec
Pavneet Singh Saund
 

More from Sven Ruppert (13)

PDF
JUnit5 Custom TestEngines intro - version 2020-06
Sven Ruppert
 
PDF
Hidden pearls for High-Performance-Persistence
Sven Ruppert
 
PDF
From Mess To Masterpiece - JFokus 2017
Sven Ruppert
 
PDF
From Jurassic Park to Microservices
Sven Ruppert
 
PDF
From jUnit to Mutationtesting
Sven Ruppert
 
PDF
DI Frameworks - hidden pearls
Sven Ruppert
 
PDF
Warum ich so auf das c von cdi stehe
Sven Ruppert
 
PDF
Proxy deep-dive java-one_20151027_001
Sven Ruppert
 
PDF
Java8 ready for the future
Sven Ruppert
 
PDF
JavaFX8 TestFX - CDI
Sven Ruppert
 
PDF
Java FX8 JumpStart - JUG ch - zürich
Sven Ruppert
 
PDF
Proxy Deep Dive JUG Saxony Day 2015-10-02
Sven Ruppert
 
PDF
Proxy Deep Dive Voxxed Belgrad 2015
Sven Ruppert
 
JUnit5 Custom TestEngines intro - version 2020-06
Sven Ruppert
 
Hidden pearls for High-Performance-Persistence
Sven Ruppert
 
From Mess To Masterpiece - JFokus 2017
Sven Ruppert
 
From Jurassic Park to Microservices
Sven Ruppert
 
From jUnit to Mutationtesting
Sven Ruppert
 
DI Frameworks - hidden pearls
Sven Ruppert
 
Warum ich so auf das c von cdi stehe
Sven Ruppert
 
Proxy deep-dive java-one_20151027_001
Sven Ruppert
 
Java8 ready for the future
Sven Ruppert
 
JavaFX8 TestFX - CDI
Sven Ruppert
 
Java FX8 JumpStart - JUG ch - zürich
Sven Ruppert
 
Proxy Deep Dive JUG Saxony Day 2015-10-02
Sven Ruppert
 
Proxy Deep Dive Voxxed Belgrad 2015
Sven Ruppert
 
Ad

Recently uploaded (20)

PPTX
How to Configure Taxes in Company Currency in Odoo 18 Accounting
Celine George
 
PDF
The Power of Compound Interest (Stanford Initiative for Financial Decision-Ma...
Stanford IFDM
 
PPTX
Elo the HeroTHIS IS A STORY ABOUT A BOY WHO SAVED A LITTLE GOAT .pptx
JoyIPanos
 
PPTX
Project 4 PART 1 AI Assistant Vocational Education
barmanjit380
 
PPTX
A Case of Identity A Sociological Approach Fix.pptx
Ismail868386
 
DOCX
ANNOTATION on objective 10 on pmes 2022-2025
joviejanesegundo1
 
PDF
Lesson 1 : Science and the Art of Geography Ecosystem
marvinnbustamante1
 
DOCX
MUSIC AND ARTS 5 DLL MATATAG LESSON EXEMPLAR QUARTER 1_Q1_W1.docx
DianaValiente5
 
PPTX
ENGLISH -PPT- Week1 Quarter1 -day-1.pptx
garcialhavz
 
PPTX
Martyrs of Ireland - who kept the faith of St. Patrick.pptx
Martin M Flynn
 
DOCX
DLL english grade five goof for one week
FlordelynGonzales1
 
PDF
Our Guide to the July 2025 USPS® Rate Change
Postal Advocate Inc.
 
PDF
Supply Chain Security A Comprehensive Approach 1st Edition Arthur G. Arway
rxgnika452
 
PPTX
How to Configure Refusal of Applicants in Odoo 18 Recruitment
Celine George
 
PPTX
How to Setup Automatic Reordering Rule in Odoo 18 Inventory
Celine George
 
PPTX
Photo chemistry Power Point Presentation
mprpgcwa2024
 
PDF
Nanotechnology and Functional Foods Effective Delivery of Bioactive Ingredien...
rmswlwcxai8321
 
PPTX
JSON, XML and Data Science introduction.pptx
Ramakrishna Reddy Bijjam
 
PPTX
How to Create & Manage Stages in Odoo 18 Helpdesk
Celine George
 
PPTX
How to Manage Wins & Losses in Odoo 18 CRM
Celine George
 
How to Configure Taxes in Company Currency in Odoo 18 Accounting
Celine George
 
The Power of Compound Interest (Stanford Initiative for Financial Decision-Ma...
Stanford IFDM
 
Elo the HeroTHIS IS A STORY ABOUT A BOY WHO SAVED A LITTLE GOAT .pptx
JoyIPanos
 
Project 4 PART 1 AI Assistant Vocational Education
barmanjit380
 
A Case of Identity A Sociological Approach Fix.pptx
Ismail868386
 
ANNOTATION on objective 10 on pmes 2022-2025
joviejanesegundo1
 
Lesson 1 : Science and the Art of Geography Ecosystem
marvinnbustamante1
 
MUSIC AND ARTS 5 DLL MATATAG LESSON EXEMPLAR QUARTER 1_Q1_W1.docx
DianaValiente5
 
ENGLISH -PPT- Week1 Quarter1 -day-1.pptx
garcialhavz
 
Martyrs of Ireland - who kept the faith of St. Patrick.pptx
Martin M Flynn
 
DLL english grade five goof for one week
FlordelynGonzales1
 
Our Guide to the July 2025 USPS® Rate Change
Postal Advocate Inc.
 
Supply Chain Security A Comprehensive Approach 1st Edition Arthur G. Arway
rxgnika452
 
How to Configure Refusal of Applicants in Odoo 18 Recruitment
Celine George
 
How to Setup Automatic Reordering Rule in Odoo 18 Inventory
Celine George
 
Photo chemistry Power Point Presentation
mprpgcwa2024
 
Nanotechnology and Functional Foods Effective Delivery of Bioactive Ingredien...
rmswlwcxai8321
 
JSON, XML and Data Science introduction.pptx
Ramakrishna Reddy Bijjam
 
How to Create & Manage Stages in Odoo 18 Helpdesk
Celine George
 
How to Manage Wins & Losses in Odoo 18 CRM
Celine George
 
Ad

Functional Reactive with Core Java - Workshop - Slides