Top Banner
DEV07 Functional Reactive Programming Alessandro Melchiori [email protected] - @amelchiori http://melkio.codiceplastico.com/
52
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Functional Reactive Programming

DEV07Functional Reactive ProgrammingAlessandro Melchiori

[email protected] - @amelchiori

http://melkio.codiceplastico.com/

Page 3: Functional Reactive Programming

Functional Reactive Programming

Page 4: Functional Reactive Programming

Functional Reactive Programming

Page 5: Functional Reactive Programming

It's declarative, stateless, side-effects free and immutable

Functional programming

Page 6: Functional Reactive Programming

It's declarative, stateless, side-effects free and immutable

Functional programming

describes what we want, not how we want

it

Page 7: Functional Reactive Programming

It's declarative, stateless, side-effects free and immutable

Functional programming

describes what we want, not how we want

it

system relys only on inputs, not external

state

Page 8: Functional Reactive Programming

It's declarative, stateless, side-effects free and immutable

Functional programming

describes what we want, not how we want

it

system relys only on inputs, not external

state

once value has been set, we can't override its

value

Return new value, instead of altering

existing ones

Page 9: Functional Reactive Programming

Give me five functions and I’ll raise up the world

[map; filter; reduce; collect; zip]

Page 10: Functional Reactive Programming

let source = [ 1; 2; 3]

let result =

List.map (fun x -> x*2) source

val result : int list = [2; 4; 6]

map

Page 11: Functional Reactive Programming

let source = [ 1; 2; 3]

let result =

List.filter (fun x -> x > 1) source

val result : int list = [2; 3]

filter

Page 12: Functional Reactive Programming

let source = [ 1; 2; 3]

let result =

List.reduce (fun acc curr -> acc + curr) source

val result : int = 6

reduce

Page 13: Functional Reactive Programming

let source = [ [ 1; 2; 3]; [ 4; 5 ] ]

let result =

List.collect (fun x -> x) source

val result : int list = [1; 2; 3; 4; 5; 6]

collect

Page 14: Functional Reactive Programming

let source1 = [ 1; 2; 3]

let source2 = [‘A’;’B’;’C’]

let result =

List.zip source1 source2

val res : (int * char) list = [(1, 'A'); (2, 'B'); (3, 'C')]

zip

Page 15: Functional Reactive Programming

Functional Reactive Programming

Page 16: Functional Reactive Programming

Functional Reactive Programming

Page 17: Functional Reactive Programming

A programming paradigm oriented around data flows

and the propagation of change.

Reactive programming

Page 18: Functional Reactive Programming

Reactive systems are responsive, resilient, elastic and message driven

Reactive manifesto (http://www.reactivemanifesto.org/)

Reactive programming

Page 19: Functional Reactive Programming

Reactive programming

1

2

sum

1diff

4

…readily responsive to a stimulus…

Page 20: Functional Reactive Programming

Reactive programming

1

1

sum

1diff

4

Page 21: Functional Reactive Programming

Reactive programming

1

1

sum

1diff

4

Page 22: Functional Reactive Programming

Reactive programming

1

1

sum

1diff

4

Page 23: Functional Reactive Programming

Reactive programming

1

1

sum

1diff

4

Page 24: Functional Reactive Programming

Reactive programming

1

1

sum

1diff

4

Page 25: Functional Reactive Programming

Reactive programming

1

1

sum

1diff

4

Page 26: Functional Reactive Programming

Reactive programming

1

1

sum

2diff

4

Page 27: Functional Reactive Programming

Reactive extensions

Page 28: Functional Reactive Programming

Rx is a library for composing asynchronous and event-based programs using observable sequences and LINQ-style query operators

(https://msdn.microsoft.com/en-us/data/gg577609.aspx)

Reactive extensions

Page 29: Functional Reactive Programming

Rx is a library for composing asynchronous and event-based programs using observable sequences and LINQ-style query operators

(https://msdn.microsoft.com/en-us/data/gg577609.aspx)

Reactive extensions

Page 30: Functional Reactive Programming

Rx is a library for composing asynchronous and event-based programs using observable sequences and LINQ-style query operators

(https://msdn.microsoft.com/en-us/data/gg577609.aspx)

Reactive extensions

Page 31: Functional Reactive Programming

Rx is a library for composing asynchronous and event-based programs using observable sequences and LINQ-style query operators

(https://msdn.microsoft.com/en-us/data/gg577609.aspx)

Reactive extensions

Page 32: Functional Reactive Programming

Rx is a library for composing asynchronous and event-based programs using observable sequences and LINQ-style query operators

(https://msdn.microsoft.com/en-us/data/gg577609.aspx)

Reactive extensions

Page 33: Functional Reactive Programming

• a set of types representing asynchronous data streams

• a set of operators to query asynchronous data streams

• a set of types to parameterize concurrency

Reactive extensions

Page 34: Functional Reactive Programming

RX = Observables + LINQ + Schedulers

Page 35: Functional Reactive Programming

demointro

Page 36: Functional Reactive Programming

Reactive extensions

Page 37: Functional Reactive Programming

Reactive extensions

publisher

Page 38: Functional Reactive Programming

Reactive extensions

publisher subscriber

Page 39: Functional Reactive Programming

Reactive extensions

publisher subscriberboth

Page 40: Functional Reactive Programming

The Observable type adds two missing semantics to the Gang of Four's Observer pattern, which are available in the Iterable type:

• The ability for the producer to signal to the consumer that there is no more data available

• The ability for the producer to signal to the consumer that an error has occurred

Reactive extensions

Page 41: Functional Reactive Programming

Reactive extensions

Page 42: Functional Reactive Programming

RX mantraeverything can be a stream

Page 43: Functional Reactive Programming

Reactive extensions: map

1 2 3 4

A B C D

Page 44: Functional Reactive Programming

Reactive extensions: filter

1 2 3 4

2 4

Page 45: Functional Reactive Programming

Reactive extensions: scan

1 2 3 4

1 3 6 10

Page 46: Functional Reactive Programming

Reactive extensions: zip

1 2 3 4

1, A 2, B 3, C 4, D

A B C D

Page 47: Functional Reactive Programming

demoClicks counter

Page 48: Functional Reactive Programming

Reactive extensions

Page 49: Functional Reactive Programming

demoAutocomplete textbox

Page 50: Functional Reactive Programming

Recap

• Functional programming

• Reactive programming

• Reactive extensions (Rx.*)

Page 51: Functional Reactive Programming

FRP is agnostic about languages. It's a mindset

Page 52: Functional Reactive Programming

Q&A

Tutto il materiale di questa sessione suhttp://www.communitydays.it/

Lascia subito il feedback su questa sessione,potrai essere estratto per i nostri premi!

Seguici suTwitter @CommunityDaysITFacebook http://facebook.com/cdaysit#CDays15