SlideShare a Scribd company logo
Functional reactive
programming
Hoang Hai Hung
1
September, 2016
Outline
1.Programming paradigms
2. Functional reactive programming
3. RxSwift
4. Demo
2
What is Programming language ?
A programming language is a notation for writing programs, which are
specifications of a computation or algorithm.
3
Programming paradigms
Pascal, C Java, C++ Haskell, Lisp Prolog
Swift 4
Imperative vs Declarative
Telling the “machine” how to do
something, and as a result what
you want to happen will happen.
Imperative programming
Telling the “machine” what you
would like to happen, and let the
computer figure out how to do it.
Declarative programming
BUT,
HOW ?
5
6
Imperative vs Declarative
Imperative programming Declarative programming
let numbers = [1, 2, 3, 4, 5, 6]
let sum = reduce(numbers, 0, +)
let odds = filter(numbers, { $0 % 2 == 1})
let array = [1, 2, 3, 4, 5, 6]
var sum = 0
var odds = []
for element in array {
sum += element
if element % 2 == 1 {
odds
.append(element)
}
}
Imperative vs Declarative
7
Imperative programming Declarative programming
Imperative vs Declarative
8
Imperative way
9
Imperative way (cont.)
10
Imperative way (cont.)
Pyramid of Doom
11
Declarative way
12
Imperative vs Declarative
Stand up, walk 10 steps by your foot to the
fridge, use your hand to open the door, get
me the water, walk back 10 steps ...
Imperative programming
Honey, i wish i had a glass of cold
water now.
Declarative programming
13
Thanks, honeyYou don’t say ?
Advantages of Declarative Programming
Minimizes mutability
Reduces state side-effects
More understandable code
More scalable
14
Outline
1. Programming paradigm
2. Functional reactive programming
3. RxSwift
4. Demo
15
Functional reactive programming (FRP)
Functional reactive programming (FRP) is a programming paradigm for
reactive programming using the building blocks of functional programming
16
Functional programming
17
Functional programming is a programming paradigm that treats computation
as the evaluation of mathematical functions and avoids changing-state and
mutable data
Functional programming
18
let numbers = [1, 2, 3, 4, 5, 6]
let doubled = numbers.map($0 * $0)
let sum = doubled.reduce(0, combine: +))
Reactive programming
Reactive programming is programming with asynchronous data streams.
19
Reactive programming
C = A + B
20
Functional reactive programming
Closure/Lambdas
Pure Function
First-Class Functions
High-Order Functions
Functional
Events/Data – Driven
Push
Asynchronous
Reactive
21
https://medium.com/@jugoncalves/functional-programming-should-be-your-1-priority-for-2015-47dd4641d6b9
https://medium.com/reactive-programming/what-is-reactive-programming-bc9fa7f4a7fc
Outline
1. Programming paradigm
2. Functional reactive programming
3. RxSwift
4. Demo
22
Stream
23
A stream is a sequence of ongoing events ordered in time.
Stream
24
Signal
25
Signal is a value that changes over time.
Example
Khi người dùng thực hiện đồng thời `di chuyển` (pan) và `xoay` vật thể
(rotate), thực hiện đếm ngược từ `3`. Dừng đếm ngược khi người dùng bỏ tay
ra hoặc đếm ngược đến 0.
26
Imperative way
27https://gist.github.com/dangthaison91/ab28bf2056f6c8a7240d073d0fb1f563#file-gesture-swift
Declarative way (FRP)
28https://gist.github.com/dangthaison91/8dc2ae412a675af322a376884f3f896e#file-gesture_frp-swift
Declarative way (FRP)
29
30
31
Example
Search on GitHub
32
Imperative way
33
Declarative way (FRP)
34
Advantages of FRP
Code more concise & clear, easy to understand without context
Readability, highly express
Make Asynchronous easier
35
36
Conclusion
37
Conclusion
38
Outline
1. Programming paradigm
2. Functional reactive programming
3. RxSwift
4. Demo
39
THANK YOU !
40

More Related Content

PPT
Hibernate presentation
PDF
Introduction to Design Pattern
PDF
Performant Streaming in Production: Preventing Common Pitfalls when Productio...
PPTX
Combine in iOS - Basics
PDF
Stream Processing with Apache Kafka and .NET
PPTX
Atlassian Bamboo Feature Overview
PPTX
ASP.MVC Training
PPT
Reactive programming with examples
Hibernate presentation
Introduction to Design Pattern
Performant Streaming in Production: Preventing Common Pitfalls when Productio...
Combine in iOS - Basics
Stream Processing with Apache Kafka and .NET
Atlassian Bamboo Feature Overview
ASP.MVC Training
Reactive programming with examples

What's hot (20)

PPTX
Design Patterns - General Introduction
PDF
Building a Streaming Microservice Architecture: with Apache Spark Structured ...
PPTX
ASP.NET Core
PDF
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
PPTX
Apache Kafka 0.8 basic training - Verisign
PDF
Introduction to Spark Streaming
PDF
Developing Real-Time Data Pipelines with Apache Kafka
PPT
Singleton design pattern
PPTX
Unit 4-apache pig
PPTX
Web frameworks
PDF
Unified Stream and Batch Processing with Apache Flink
PPTX
Java web application development
PDF
Hibernate Presentation
PPT
Introduction to the Web API
PDF
Microservice Architecture Patterns, by Richard Langlois P. Eng.
PDF
18 Data Streams
PDF
Infrastructure as Code on AWS
PDF
Android Data Persistence
PPTX
Squirreling Away $640 Billion: How Stripe Leverages Flink for Change Data Cap...
PPTX
Java Server Pages(jsp)
Design Patterns - General Introduction
Building a Streaming Microservice Architecture: with Apache Spark Structured ...
ASP.NET Core
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Apache Kafka 0.8 basic training - Verisign
Introduction to Spark Streaming
Developing Real-Time Data Pipelines with Apache Kafka
Singleton design pattern
Unit 4-apache pig
Web frameworks
Unified Stream and Batch Processing with Apache Flink
Java web application development
Hibernate Presentation
Introduction to the Web API
Microservice Architecture Patterns, by Richard Langlois P. Eng.
18 Data Streams
Infrastructure as Code on AWS
Android Data Persistence
Squirreling Away $640 Billion: How Stripe Leverages Flink for Change Data Cap...
Java Server Pages(jsp)
Ad

Similar to Functional reactive programming (20)

PDF
Python functional programming
PPTX
Functional pogramming hl overview
PDF
Functional Programming in R
PPT
Introduction Functional Programming - Tech Hangout #11 - 2013.01.16
PPT
Introductory func prog
PPTX
Prgramming paradigms
PDF
379008-rc217-functionalprogramming
PPT
Inroduction to r
PPT
Programming Paradigms
PDF
Compiler Construction for DLX Processor
PDF
Google Interview Questions By Scholarhat
PDF
Python Programming - II. The Basics
PDF
Introduction to functional programming
PDF
PHP Reactive Programming at Medan Tech Day 2018
PPTX
Dev Concepts: Functional Programming
PPTX
1_Introduction.pptx
PPT
Programming Paradigms
PPTX
R Programming Language
PPTX
R4ML: An R Based Scalable Machine Learning Framework
PDF
Async/Await Best Practices
Python functional programming
Functional pogramming hl overview
Functional Programming in R
Introduction Functional Programming - Tech Hangout #11 - 2013.01.16
Introductory func prog
Prgramming paradigms
379008-rc217-functionalprogramming
Inroduction to r
Programming Paradigms
Compiler Construction for DLX Processor
Google Interview Questions By Scholarhat
Python Programming - II. The Basics
Introduction to functional programming
PHP Reactive Programming at Medan Tech Day 2018
Dev Concepts: Functional Programming
1_Introduction.pptx
Programming Paradigms
R Programming Language
R4ML: An R Based Scalable Machine Learning Framework
Async/Await Best Practices
Ad

Recently uploaded (20)

PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
MYSQL Presentation for SQL database connectivity
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Machine learning based COVID-19 study performance prediction
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Big Data Technologies - Introduction.pptx
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Approach and Philosophy of On baking technology
PPTX
Cloud computing and distributed systems.
PPT
Teaching material agriculture food technology
Encapsulation_ Review paper, used for researhc scholars
MYSQL Presentation for SQL database connectivity
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Mobile App Security Testing_ A Comprehensive Guide.pdf
Spectral efficient network and resource selection model in 5G networks
Machine learning based COVID-19 study performance prediction
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Big Data Technologies - Introduction.pptx
Unlocking AI with Model Context Protocol (MCP)
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
20250228 LYD VKU AI Blended-Learning.pptx
Approach and Philosophy of On baking technology
Cloud computing and distributed systems.
Teaching material agriculture food technology

Functional reactive programming