introduction to functional reactive programming

50
Reactive Thinking fb.me/dangthaison.91 | @dangthaison91

Upload: dang-thai-son

Post on 09-Jan-2017

1.975 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Introduction to Functional Reactive Programming

Reactive Thinking

fb.me/dangthaison.91 | @dangthaison91

Page 2: Introduction to Functional Reactive Programming

FunctionalReactive

Programming

Page 3: Introduction to Functional Reactive Programming

1. What is FRP?

Page 4: Introduction to Functional Reactive Programming

Functional+

Reactive

Page 5: Introduction to Functional Reactive Programming

Microsoft Excel

Page 6: Introduction to Functional Reactive Programming

a = b + c

Page 7: Introduction to Functional Reactive Programming

FRP: Streams of values over time

Page 8: Introduction to Functional Reactive Programming
Page 9: Introduction to Functional Reactive Programming

Core of FRP is Signal

Page 10: Introduction to Functional Reactive Programming

Signal emits value over the

time

Page 11: Introduction to Functional Reactive Programming

FRPis

Declarative

Page 12: Introduction to Functional Reactive Programming

Imperative

Write correct sequence of codes in the correct order. Step by step. (How)

Declarative

Write code to describes what you want to do.

Page 13: Introduction to Functional Reactive Programming

2. Why is FRP?

Page 14: Introduction to Functional Reactive Programming

Example 1

Search API as you type but:

- Don't spam API server every seconds- Only make request if keyword changed- Cancel previous requests

Page 15: Introduction to Functional Reactive Programming

Imperative

Page 16: Introduction to Functional Reactive Programming

Declarative

Page 17: Introduction to Functional Reactive Programming
Page 18: Introduction to Functional Reactive Programming
Page 19: Introduction to Functional Reactive Programming
Page 20: Introduction to Functional Reactive Programming

Example 2

When the user starts simultaneously panning and rotating an object, start a countdown from 3.

Stop the timer either when the countdown ends or when the user stops the gestures.

Page 21: Introduction to Functional Reactive Programming

Imperative

Page 22: Introduction to Functional Reactive Programming

Imperative

Page 23: Introduction to Functional Reactive Programming

Imperative

- When the user touches the screen - Check if a user is panning an object, store that information - Check if both gestures are running simultaneously - start a timer, from 3, counting down. - Check if the user is rotating an object, store that information - Check if both gestures are running simultaneously - start a timer, from 3, counting down. - Check if the user stopped panning - Stop the timer if needed - Check if the user stopped rotating - Stop the timer if needed

- When the timer ticks, decrease the number of seconds left - If the number of seconds left is zero, stop the timer*

Page 24: Introduction to Functional Reactive Programming

There is a Better Way!

Page 25: Introduction to Functional Reactive Programming

Declarative

Page 26: Introduction to Functional Reactive Programming

Declarative

Page 27: Introduction to Functional Reactive Programming

Declarative

Page 28: Introduction to Functional Reactive Programming
Page 29: Introduction to Functional Reactive Programming
Page 30: Introduction to Functional Reactive Programming

Declarative

Page 31: Introduction to Functional Reactive Programming

Declarative

Page 32: Introduction to Functional Reactive Programming

Declarative

Define condition “simultaneously `panning` and `rotating`”Define condition “start a countdown from `3`”Define condition “when the user stops the gestures”Define what a timer is

When the user starts simultaneously `panning` and `rotating` an object, start a countdown from `3`.Stop the timer either when the countdown ends or when the user stops the gestures.”

Page 33: Introduction to Functional Reactive Programming

Advantages• Code more concise & clear, easy to

understand without context

• Readability, highly express

• Make Asynchronous easier

• UI Binding

• Maintainability, Extensibility...

Page 34: Introduction to Functional Reactive Programming

Imperative

Page 35: Introduction to Functional Reactive Programming

Declarative

Page 36: Introduction to Functional Reactive Programming

What we can do• Observables

• Transformations

• Composition

• Combination

• Filter

• Buffer...

Page 37: Introduction to Functional Reactive Programming
Page 38: Introduction to Functional Reactive Programming

Denial• FRP is hard, imperative is more easier

• FRP just is trend!

• Just another Framework

• Unnecessarily complex

Page 39: Introduction to Functional Reactive Programming
Page 40: Introduction to Functional Reactive Programming

3. Thinking in Reactive

Page 41: Introduction to Functional Reactive Programming

FRP is hard, but it is SIMPLE

Page 42: Introduction to Functional Reactive Programming

Imperative is EASY

Page 43: Introduction to Functional Reactive Programming

Simplevs

Easy

Page 44: Introduction to Functional Reactive Programming

Complexity

Page 45: Introduction to Functional Reactive Programming

Simple made Easy— Rick Hickey

Page 46: Introduction to Functional Reactive Programming

FRP is good Trend

Page 47: Introduction to Functional Reactive Programming

Functional Reactive will be

RADIOACTIVE

Page 48: Introduction to Functional Reactive Programming

More: https://goo.gl/lfNWlJBlog: https://dangthaison91.wordpress.com

Page 49: Introduction to Functional Reactive Programming

Thank you!

Page 50: Introduction to Functional Reactive Programming