Slide 1

Slide 1 text

Functional Reactive Programming in Swift X140Yu@Zhihu 2017/05

Slide 2

Slide 2 text

What is FRP?

Slide 3

Slide 3 text

FRP Functional Reactive

Slide 4

Slide 4 text

FRP Functional Reactive first class and higher-order functions pure functions Example

Slide 5

Slide 5 text

FRP Functional Reactive first class and higher-order functions pure functions asynchronous data streams touch event, KVO, Notification, callback, Network response,timer

Slide 6

Slide 6 text

Functional Reactive + Stream Transform Binding

Slide 7

Slide 7 text

Stream Like a pipe, if you missed the thing through it, it's gone forever Like an Array, it can hold anything Unlike an Array, you can't access it anytime you want, instread, you get notified when it's value get changed

Slide 8

Slide 8 text

Functional Reactive + Stream Transform Binding

Slide 9

Slide 9 text

Transform Higher-order functions, map, filter, reduce, flatMap, etc Change a stream to another stream, just like change a sequence to another Write our own version of there functions!

Slide 10

Slide 10 text

Functional Reactive + Stream Transform Binding

Slide 11

Slide 11 text

Binding Without binding, all the efforts are useless it makes the program more reactive

Slide 12

Slide 12 text

Functional Reactive + Stream Transform Binding

Slide 13

Slide 13 text

Functional Reactive + + Swift

Slide 14

Slide 14 text

Functional Reactive + + Swift Functional language Compiler & strong typed

Slide 15

Slide 15 text

Functional Reactive + + Swift Functional language Compiler & strong typed Write awesome program!

Slide 16

Slide 16 text

Functional Reactive + + Swift Improve productivity Less and more centralised code Easy to maintain Good Bad Learning curve is steep, but not that steep Debug may be difficult Change the way you think when coding Avoid complexity with mutable state growing over time

Slide 17

Slide 17 text

How

Slide 18

Slide 18 text

A simple demo Email validation

Slide 19

Slide 19 text

The unit of reactive programming Observable Subscriber

Slide 20

Slide 20 text

The unit of reactive programming Observable Subscriber 1

Slide 21

Slide 21 text

The unit of reactive programming Observable Subscriber 1

Slide 22

Slide 22 text

Observable: send messages Subscriber: consume messages The unit of reactive programming

Slide 23

Slide 23 text

Observable The unit of reactive programming Sequence What is sequence? Demo

Slide 24

Slide 24 text

The unit of reactive programming Implement our own Observable/Subscriber pattern?

Slide 25

Slide 25 text

Use a library instead! ReactiveSwift/ReactiveCocoa ReactiveKit RxSwift/RxCocoa Why I choose RxSwift?

Slide 26

Slide 26 text

To be continued……