Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Let's be functional-reactive in Cocoa world
Search
Igor Vasilenko
July 17, 2016
Programming
0
120
Let's be functional-reactive in Cocoa world
Slides from talk on MO Conf 2016
mo.dev.by
Igor Vasilenko
July 17, 2016
Tweet
Share
More Decks by Igor Vasilenko
See All by Igor Vasilenko
ReactiveCocoa. As all silent
spbvasilenko
0
64
Other Decks in Programming
See All in Programming
Quand Symfony, ApiPlatform, OpenAI et LangChain s'allient pour exploiter vos PDF : de la théorie à la production…
ahmedbhs123
0
210
AIともっと楽するE2Eテスト
myohei
7
2.8k
初学者でも今すぐできる、Claude Codeの生産性を10倍上げるTips
s4yuba
16
12k
코딩 에이전트 체크리스트: Claude Code ver.
nacyot
0
690
ご注文の差分はこちらですか? 〜 AWS CDK のいろいろな差分検出と安全なデプロイ
konokenj
2
120
Flutterで備える!Accessibility Nutrition Labels完全ガイド
yuukiw00w
0
170
20250704_教育事業におけるアジャイルなデータ基盤構築
hanon52_
5
840
Goで作る、開発・CI環境
sin392
0
240
技術同人誌をMCP Serverにしてみた
74th
1
660
AIと”コードの評価関数”を共有する / Share the "code evaluation function" with AI
euglena1215
1
170
明示と暗黙 ー PHPとGoの インターフェイスの違いを知る
shimabox
2
530
Claude Code + Container Use と Cursor で作る ローカル並列開発環境のススメ / ccc local dev
kaelaela
10
6k
Featured
See All Featured
Measuring & Analyzing Core Web Vitals
bluesmoon
7
510
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
31
1.3k
Site-Speed That Sticks
csswizardry
10
690
BBQ
matthewcrist
89
9.7k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
20
1.3k
Why You Should Never Use an ORM
jnunemaker
PRO
58
9.4k
Docker and Python
trallard
44
3.5k
Making the Leap to Tech Lead
cromwellryan
134
9.4k
Building Flexible Design Systems
yeseniaperezcruz
328
39k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
30
2.1k
Rails Girls Zürich Keynote
gr2m
95
14k
Intergalactic Javascript Robots from Outer Space
tanoku
271
27k
Transcript
Let’s be functional-reactive in Cocoa world
About me iOS developer at YOTA Official member of Typhoon
framework vasilenkoigor i_vasilenko igorvasilenko.me
Agenda FRP explained ReactiveCocoa explained Practice with RAC RAC vs.
RxSwift Conclusion
Agenda FRP explained ReactiveCocoa explained Practice with RAC RAC vs.
RxSwift Conclusion
FRP explained
FRP explained «Is a programming paradigm for reactive programming using
the building blocks of functional programming.» - Wikipedia
None
FRP explained #BULLSHIT
FRP explained • Reactive programming is programming with asynchronous data
streams • Amazing toolbox of functions to combine, create and filter any of those streams Let’s cut the bullshit
x: 10 x: 20 x: 30 x: 40 x: 50
Data stream
FRP explained • Reactive programming is programming with asynchronous data
streams • Amazing toolbox of functions to combine, create and filter any of those streams Let’s cut the bullshit
FRP explained Why should you consider adopting RP? • Code
will likely be more concise • Efficiency • Architecture • Hot-swapping • Binding
Agenda FRP explained ReactiveCocoa explained Practice with RAC RAC vs.
RxSwift Conclusion
Agenda FRP explained ReactiveCocoa explained Practice with RAC RAC vs.
RxSwift Conclusion
ReactiveCocoa explained
ReactiveCocoa explained • ReactiveCocoa (RAC) is a framework developed by
GitHub • ReactiveCocoa is an implementation FRP on iOS/macOS • Currently framework version - 4.2.1
ReactiveCocoa explained Signals Signal is an object that can emit
Events.
ReactiveCocoa explained Signals public final class Signal<Value, Error: ErrorType>
ReactiveCocoa explained Signals let mySignal = Signal<Int, NSError>({ observer in
observer.sendNext(1) observer.sendNext(2) /* send other events to observer */ return nil })
ReactiveCocoa explained Events There are four types of events that
a signal can emit
ReactiveCocoa explained Events Next(Value) events are most common ones. They
carry a certain value;
ReactiveCocoa explained Events Completed event signals the successful completion of
a signal;
ReactiveCocoa explained Events Failed(Error) event carries an error object that
reflects the reason of failed signal completion;
ReactiveCocoa explained Events Interrupted is a termination event that signifies
neither a successful, nor failed completion of a signal.
ReactiveCocoa explained Timeline of Events /^Next*(Failed|Completed|Interrupted)?$/
ReactiveCocoa explained Observers You can think of observers as functions
that do something with event when it arrives.
ReactiveCocoa explained Observers • observeNext: observe only Next events carrying
a value • observeFailed: observe only Failed event that carry an error object • observeCompleted: observe only signal completion event
ReactiveCocoa explained Pipes In the days of RAC 2.x this
used to be represented by RACSubject class instances. let (signal, observer) = Signal<Int, NSError>.pipe()
ReactiveCocoa explained Pipes signal.observeNext({ print($0)}) observer.sendNext(0) // prints "0" observer.sendNext(1)
// prints "1"
ReactiveCocoa explained Operators map: changes function from one type to
another or modifies the value retaining the type someSignal.map { (intValue) -> String in return "value: \(intValue)" }
ReactiveCocoa explained Operators filter: forwards only the values that pass
a given predicate closure; someSignal.filter { (intValue) -> Bool in return intValue > 0 }
ReactiveCocoa explained Operators take: takes up to N values sent
by the signal someSignal.take(1).observeNext { (intValue) in // Next event will be once received }
ReactiveCocoa explained Operators throttle: sends new signal’s values no more
often than provided time interval someSignal.throttle(30,onScheduler:UIScheduler())
ReactiveCocoa explained Operators let combineSignals = combineLatest(numbersSignal,lettersSignal) .on { (intValue,
stringValue) in print(intValue) print(stringValue) } combineLatest: a free function that combines values from variable number of signals
ReactiveCocoa explained Operators combineSignals.reduce("", { (startValue, valuesTuple) in return valuesTuple.1
}).observeNext { (stringValue) in print(stringValue) } reduce: upon signal completion combines all sent values using provided function
ReactiveCocoa explained SignalProducers You’d want a pull-driven stream of events
so that you could receive events on demand.
ReactiveCocoa explained SignalProducers SignalProducer <String, NSError> {(observer, disposable) in ///
some task (api request, saving to database, etc.) }
ReactiveCocoa explained SignalProducers Another big difference of the SignalProducer is
that it can contain side-effects.
ReactiveCocoa explained SignalProducers producer.on(started: { /// Some work }, event:
{ (event) in /// Some work }) other side-effects: failed, interrupted, completed, terminated, disposed
ReactiveCocoa explained MutableProperty Mutable property is a concrete implementation of
read-write property and is probably mostly used type among other ones. var bankAccountBalance = MutableProperty<Double>(100)
ReactiveCocoa explained MutableProperty bankAccountBalance.value = 200; bankAccountBalance.signal.observeNext { (value) in
/// Some work } Observe and change value
ReactiveCocoa explained Schedulers When receiving a signal or producer from
unknown code, it can be difficult to know which thread events will arrive upon.
ReactiveCocoa explained Schedulers someSignal.observeOn(UIScheduler()).observeNext { (value) in /// observe on
Main Thread } Whenever such a guarantee is important, the observeOn operator should be used to force events to be received upon a specific scheduler.
ReactiveCocoa explained Schedulers Schedulers are similar to Grand Central Dispatch
queues, but schedulers support cancellation (via disposables), and always execute serially.
Agenda FRP explained ReactiveCocoa explained Practice with RAC RAC vs.
RxSwift Conclusion
Agenda FRP explained ReactiveCocoa explained Practice with RAC RAC vs.
RxSwift Conclusion
Practice with RAC github.com/vasilenkoigor/MOConf2016Practice
Agenda FRP explained ReactiveCocoa explained Practice with RAC RAC vs.
RxSwift Conclusion
Agenda FRP explained ReactiveCocoa explained Practice with RAC RAC vs.
RxSwift Conclusion
RAC vs. RxSwift
RAC vs. RxSwift • ReactiveX - a group which created
a common API for FRP implementations • RxSwift is a relatively recent addition to ReactiveX • Currently framework version - 2.6.0
RAC vs. RxSwift Hot and cold RxSwift doesn’t support differentiate
between hot and cold signals Observable <String>.just("Say hello RxSwift")
RAC vs. RxSwift Error handling RxSwift doesn’t support parameterized type
for the error case Observable <T>
RAC vs. RxSwift UI bindings • RxSwift bindings are a
joy to use • ReactiveCocoa bindings only with custom extensions
RAC vs. RxSwift RAC in big projects? • WhatsApp •
Github • Yota • Yandex • SoundCloud
RAC vs. RxSwift Why YOTA using ReactiveCocoa? • We want
to be able to better describe our system • We want having different types to differentiate between hot and cold signals • We want a battle tested framework, used by many people, in many projects
Agenda FRP explained ReactiveCocoa explained Practice with RAC RAC vs.
RxSwift Conclusion
Agenda FRP explained ReactiveCocoa explained Practice with RAC RAC vs.
RxSwift Conclusion
Thank you! <3