Slide 1

Slide 1 text

Functional Reactive iOS

Slide 2

Slide 2 text

Functional Reactive iOS

Slide 3

Slide 3 text

Functional Reactive OSX

Slide 4

Slide 4 text

Functional Reactive .NET

Slide 5

Slide 5 text

Functional Reactive JS

Slide 6

Slide 6 text

Functional Reactive

Slide 7

Slide 7 text

Functional Reactive Why you should consider programming

Slide 8

Slide 8 text

@iwantmyrealname

Slide 9

Slide 9 text

iwantmyreal.name

Slide 10

Slide 10 text

leanpub.com/ios7daybyday

Slide 11

Slide 11 text

@shinobicontrols

Slide 12

Slide 12 text

shinobicontrols.com

Slide 13

Slide 13 text

what is functional reactive programming?

Slide 14

Slide 14 text

what is functional reactive programming?

Slide 15

Slide 15 text

programming

Slide 16

Slide 16 text

computer programming is a process that leads from an original formulation of a computing problem to executable programs programming

Slide 17

Slide 17 text

what is functional reactive programming?

Slide 18

Slide 18 text

functional

Slide 19

Slide 19 text

functional stateless immutable 1st class functions

Slide 20

Slide 20 text

what is functional reactive programming?

Slide 21

Slide 21 text

reactive

Slide 22

Slide 22 text

reactive dataflow spreadsheets

Slide 23

Slide 23 text

what is functional reactive programming?

Slide 24

Slide 24 text

frp obvious

Slide 25

Slide 25 text

frp immutable events functional pipeline reactive signals

Slide 26

Slide 26 text

frp a standard interface for events

Slide 27

Slide 27 text

signals

Slide 28

Slide 28 text

signals what are

Slide 29

Slide 29 text

represent a stream of immutable events signals

Slide 30

Slide 30 text

events are signals next completed error

Slide 31

Slide 31 text

signals what can model?

Slide 32

Slide 32 text

delegation observer/databinding target-action blocks/lambdas/closures modelling

Slide 33

Slide 33 text

async tasks network events user interaction flow control modelling

Slide 34

Slide 34 text

signals what can be used for?

Slide 35

Slide 35 text

signals most useful when a functional pipeline is formed uses

Slide 36

Slide 36 text

map filter combine buffer signal operations zip concat takeUntil …

Slide 37

Slide 37 text

real world example

Slide 38

Slide 38 text

demo

Slide 39

Slide 39 text

example username password s sa sam p pa pas pass submit

Slide 40

Slide 40 text

example username password s sa sam p pa pas pass submit username password 1 2 3 1 2 3 4 string.length map

Slide 41

Slide 41 text

example username password s sa sam p pa pas pass submit username password 3 3 4 greater than 2 filter

Slide 42

Slide 42 text

example let usernameSignal = tf.rac_textSignal() .mapAs({ (value: NSString) -> NSNumber in return value.length }) .filterAs({ (value: NSNumber) -> Bool in return value.intValue > 2 })

Slide 43

Slide 43 text

example let usernameSignal = tf.rac_textSignal() .mapAs({ (value: NSString) -> NSNumber in return value.length }) .filterAs({ (value: NSNumber) -> Bool in return value.intValue > 2 })

Slide 44

Slide 44 text

example let usernameSignal = tf.rac_textSignal() .mapAs({ (value: NSString) -> NSNumber in return value.length }) .filterAs({ (value: NSNumber) -> Bool in return value.intValue > 2 })

Slide 45

Slide 45 text

example RACSignal.combineLatest([usernameSignal, passwordSignal]) .subscribeNext({ (value: AnyObject!) in button.enabled = true })

Slide 46

Slide 46 text

example RACSignal.combineLatest([usernameSignal, passwordSignal]) .subscribeNext({ (value: AnyObject!) in button.enabled = true })

Slide 47

Slide 47 text

more interesting example

Slide 48

Slide 48 text

example connect to a websocket which streams live edits from wikipedia

Slide 49

Slide 49 text

example RESPONSE: { "type":"unspecified", "content":"Wikipedia talk:Articles for creation/Bonnie ZoBell", “time":"2014-05-15T14:45:59.175Z" } RESPONSE: { "type":"unspecified", "content":"Wikipedia:WikiProject Spam/LinkReports/blog.wifirst.fr", “time":"2014-05-15T14:45:59.247Z" } RESPONSE: { "type":"special", "content":"", “time":"2014-05-15T14:46:00.262Z" } RESPONSE: { "type":"unspecified", "content":"Manhattan Film Academy", “time":"2014-05-15T14:46:00.828Z" }

Slide 50

Slide 50 text

example show the names of the edited pages

Slide 51

Slide 51 text

filter to get “unspecified” map to extract “content” subscribe and update label example

Slide 52

Slide 52 text

example wsConnector.messages .filterAs({ (dict: NSDictionary) in return (dict["type"] as NSString).isEqualToString("unspecified") }) .mapAs({ (dict: NSDictionary) -> NSString in return dict["content"] as NSString }) .deliverOn(RACScheduler.mainThreadScheduler()) .subscribeNextAs({(value: NSString) in self.tickerLabel.text = value })

Slide 53

Slide 53 text

example wsConnector.messages .filterAs({ (dict: NSDictionary) in return (dict["type"] as NSString).isEqualToString("unspecified") }) .mapAs({ (dict: NSDictionary) -> NSString in return dict["content"] as NSString }) .deliverOn(RACScheduler.mainThreadScheduler()) .subscribeNextAs({(value: NSString) in self.tickerLabel.text = value })

Slide 54

Slide 54 text

example wsConnector.messages .filterAs({ (dict: NSDictionary) in return (dict["type"] as NSString).isEqualToString("unspecified") }) .mapAs({ (dict: NSDictionary) -> NSString in return dict["content"] as NSString }) .deliverOn(RACScheduler.mainThreadScheduler()) .subscribeNextAs({(value: NSString) in self.tickerLabel.text = value })

Slide 55

Slide 55 text

example plot the live edit rate on a chart

Slide 56

Slide 56 text

buffer to collect sample map to count samples subscribe to add to chart example

Slide 57

Slide 57 text

example wsConnector.messages .bufferWithTime(5, onScheduler: scheduler) .mapAs({ (value: RACTuple) -> NSNumber in return NSNumber(double: Double(value.count) / 5.0) }) .deliverOn(RACScheduler.mainThreadScheduler()) .logNext() .subscribeNext({(x: AnyObject!) in self.datasource!.appendValue(x as NSNumber) })

Slide 58

Slide 58 text

example wsConnector.messages .bufferWithTime(5, onScheduler: scheduler) .mapAs({ (value: RACTuple) -> NSNumber in return NSNumber(double: Double(value.count) / 5.0) }) .deliverOn(RACScheduler.mainThreadScheduler()) .logNext() .subscribeNext({(x: AnyObject!) in self.datasource!.appendValue(x as NSNumber) })

Slide 59

Slide 59 text

example wsConnector.messages .bufferWithTime(5, onScheduler: scheduler) .mapAs({ (value: RACTuple) -> NSNumber in return NSNumber(double: Double(value.count) / 5.0) }) .deliverOn(RACScheduler.mainThreadScheduler()) .logNext() .subscribeNext({(x: AnyObject!) in self.datasource!.appendValue(x as NSNumber) })

Slide 60

Slide 60 text

example annotate new-user events on the chart

Slide 61

Slide 61 text

filter to get “newuser” map to create annotation subscribe to add to chart example

Slide 62

Slide 62 text

example wsConnector.messages .filterAs({ (value: NSDictionary) -> Bool in return (value["type"] as NSString).isEqualToString("newuser") }) .mapAs({ (value: NSDictionary) -> SChartAnnotation in return self.createNewUserAnnotation(value["time"]) }) .deliverOn(RACScheduler.mainThreadScheduler()) .subscribeNextAs({ (value: SChartAnnotation) in self.chart.addAnnotation(value) self.chart.redrawChart() })

Slide 63

Slide 63 text

example wsConnector.messages .filterAs({ (value: NSDictionary) -> Bool in return (value["type"] as NSString).isEqualToString("newuser") }) .mapAs({ (value: NSDictionary) -> SChartAnnotation in return self.createNewUserAnnotation(value["time"]) }) .deliverOn(RACScheduler.mainThreadScheduler()) .subscribeNextAs({ (value: SChartAnnotation) in self.chart.addAnnotation(value) self.chart.redrawChart() })

Slide 64

Slide 64 text

example wsConnector.messages .filterAs({ (value: NSDictionary) -> Bool in return (value["type"] as NSString).isEqualToString("newuser") }) .mapAs({ (value: NSDictionary) -> SChartAnnotation in return self.createNewUserAnnotation(value["time"]) }) .deliverOn(RACScheduler.mainThreadScheduler()) .subscribeNextAs({ (value: SChartAnnotation) in self.chart.addAnnotation(value) self.chart.redrawChart() })

Slide 65

Slide 65 text

demo

Slide 66

Slide 66 text

in summary

Slide 67

Slide 67 text

cool functional reactive programming is

Slide 68

Slide 68 text

powerful functional reactive programming is

Slide 69

Slide 69 text

fun functional reactive programming is

Slide 70

Slide 70 text

you should give it a try

Slide 71

Slide 71 text

you should give it a try ReactiveCocoa

Slide 72

Slide 72 text

you should give it a try ReactiveExtensions

Slide 73

Slide 73 text

you should give it a try Elm

Slide 74

Slide 74 text

thanks github.com/sammyd @iwantmyrealname