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
λ is coming to Obj-C – ReactiveCocoa
Search
Vladimir Burdukov
February 24, 2014
Programming
1
120
λ is coming to Obj-C – ReactiveCocoa
Vladimir Burdukov
February 24, 2014
Tweet
Share
More Decks by Vladimir Burdukov
See All by Vladimir Burdukov
Alice in robovacuum land
chipp
0
55
It’s time to migrate from RxSwift to Combine. Long story short
chipp
0
68
Decodable vs real-world JSON
chipp
0
55
`fastlane beta` 2 или почему я стал пить больше кофе
chipp
0
500
`fastlane beta` или почему я стал пить больше кофе
chipp
0
130
Архитектурные излишества в iOS приложениях Superjob
chipp
0
160
λ is coming to Obj-C – ReactiveCocoa
chipp
0
350
Build bots
chipp
0
120
Other Decks in Programming
See All in Programming
GitHub Actionsのキャッシュと手を挙げることの大切さとそれに必要なこと
satoshi256kbyte
5
420
Tuning GraphQL on Rails
pyama86
2
1.2k
受け取る人から提供する人になるということ
little_rubyist
0
200
ActiveSupport::Notifications supporting instrumentation of Rails apps with OpenTelemetry
ymtdzzz
1
190
AI時代におけるSRE、 あるいはエンジニアの生存戦略
pyama86
4
1k
Generative AI Use Cases JP (略称:GenU)奮闘記
hideg
0
190
광고 소재 심사 과정에 AI를 도입하여 광고 서비스 생산성 향상시키기
kakao
PRO
0
170
WebフロントエンドにおけるGraphQL(あるいはバックエンドのAPI)との向き合い方 / #241106_plk_frontend
izumin5210
4
1.3k
僕がつくった48個のWebサービス達
yusukebe
20
17k
開発効率向上のためのリファクタリングの一歩目の選択肢 ~コード分割~ / JJUG CCC 2024 Fall
ryounasso
0
430
Jakarta EE meets AI
ivargrimstad
0
220
Realtime API 入門
riofujimon
0
140
Featured
See All Featured
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
26
2.1k
Mobile First: as difficult as doing things right
swwweet
222
8.9k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
1.8k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.8k
Producing Creativity
orderedlist
PRO
341
39k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
Six Lessons from altMBA
skipperchong
27
3.5k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
700
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
Fireside Chat
paigeccino
33
3k
Building Your Own Lightsaber
phodgson
102
6.1k
Designing on Purpose - Digital PM Summit 2013
jponch
115
7k
Transcript
λ is coming to Obj-C: ReactiveCocoa Vladimir @chippcheg Burdukov
Imperative
Declarative
Functional programming λ-calculus
Functional programming
Pure function • result doesn’t depend on any state •
function doesn’t change any external state.
Pure function def sqr(x: Int): Int = x * x
//> sqr: (x: Int)Int sqr(2) /> res4: Int = 4 def add1(x: Int): Int = x + 1 //> add1: (x: Int)Int add1(4) //> res3: Int = 5 add1(add1(4)) //> res4: Int = 6
Higher-order functions
Higher-order functions def sqr(x: Int): Int = x * x
def sumF(x: Int, y: Int, f: Int => Int) = f(x) + f(y) sumF(3, 4, sqr) //> res5: Int = 25
Higher-order functions def sqr(x: Int): Int = x * x
def sumF(x: Int, y: Int, f: Int => Int) = f(x) + f(y) sumF(3, 4, sqr) //> res5: Int = 25 sumF(-9, 16, abs) //> res6: Int = 25
Tail recursion
Tail recursion Lists Head Tail
Tail recursion Lists val foo: List[Int] = 1 to 5
toList //> foo : List[Int] = List(1, 2, 3, 4, 5) val foohead = foo.head //> foohead : Int = 1 val footail = foo.tail //> footail : List[Int] = List(2, 3, 4, 5)
Tail recursion def sumList(xs: List[Int]): Int = if (xs ==
Nil) return 0 else return xs.head + sumList(xs.tail) // > sumList: (xs: List[Int])Int ! sumList(foo) //> res3: Int = 15
Composition
Composition def f(a: String): String = "f(" + a +
")" f("5") //> res11: String = f(5) def g(a: String): String = "g(" + a + “)" g("5") //> res12: String = g(5) f(g("5")) //> res13: String = f(g(5)) def fg = f _ compose g _ //> fg: => String => String fg("5") //> res14: String = f(g(5))
Functional programming References •https://www.coursera.org/course/progfun
Reactive Programming
Reactive Programming 5 10 =SUM(A1;B1) A1 B1 C1
Functional Reactive Programming
ReactiveCocoa Next step of Objective-C evolution https://github.com/ReactiveCocoa/ReactiveCocoa/
Introduction https://github.com/ReactiveCocoa/ReactiveCocoa/blob/master/Documentation/
Introduction https://github.com/ReactiveCocoa/ReactiveCocoa/blob/master/Documentation/ pod
RACSequense RACSignal
RACSignal
RACSignal UISwitch *settingSwitch = [[UISwitch alloc] init]; RACSignal *switchSignal =
[settingSwitch rac_signalForControlEvents:UIControlEventValueChanged]; [switchSignal subscribeNext:^(UISwitch *x) { NSLog(@"SWITCH %@", x.on); }]; //SWITCH 0 //SWITCH 1 //SWITCH 0
RACSignal signal subscribeNext:
RACSignal Composition [[[self.field rac_textSignal] filter:^BOOL(NSString *value) { return value.length >=
8; }] subscribeNext:^(id x) { NSLog(@"%@", x); }];
RACSignal Combining signal signal combine reduce YES/NO NSString NSString
RACSignal Combining RAC(self.createButton, enabled) = [RACSignal combineLatest:@[self.loginField.rac_textSignal, self.passwordField.rac_textSignal] reduce:^id(NSString *username,
NSString *password) { return @(username.length > 0 && password.length > 0); }];
RACSequence
Binding RAC(self.avatarImageView, image) = RACObserve(self.viewModel, userAvatar);
ReactiveCocoa UI extensions • UIActionSheet / UIAlertView • UIButton •
UITableViewCell • UIControl (rac_signalForControlEvents:) • UIGestureRecognizer • UITextField
UIAlertView Signal UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Something goes
wrong" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:@"Retry", nil]; ! [[alertView rac_buttonClickedSignal] subscribeNext:^(NSNumber *buttonNumber) { NSLog(@"alert button: %@", [alertView buttonTitleAtIndex:buttonNumber.intValue]); }];
UIButton Command RACCommand *loginCommand = [[RACCommand alloc] initWithEnabled:[RACSignal combineLatest:@[loginField.rac_textSignal, passwordField.rac_textSignal]
reduce:^id(NSString *username, NSString *password) { return @(username.length > 0 && password.length > 0); }] signalBlock:^RACSignal *(id input) { return [[JMHSync shared] loginUser:self.loginField.text withPassword:self.passwordField.text]; }]; ! self.createButton.rac_command = loginCommand;
UITextField Signal [self.loginField.rac_textSignal subscribeNext:^(NSString *x) { NSLog(@"you entered %@", x);
}];
Conclusion
Questions
Thank you!