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
Rui Peres: Testing FRP Code
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Realm
July 08, 2016
Technology
83
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Rui Peres: Testing FRP Code
Realm
July 08, 2016
More Decks by Realm
See All by Realm
WWDC 2017 Review
realm
0
2.2k
Xcode shortcuts
realm
0
4.8k
Self Branding with GitHub
realm
0
4.4k
Realm Mobile Platform overview and demo
realm
0
2.1k
Realm advanced topics and demo
realm
0
2k
Realm introduction Seoul meetup 10
realm
0
2.2k
Stuart Hall: How I got 2.3 Million App Downloads
realm
0
2k
James Majors: What the Swiftly Func?
realm
1
4.3k
Simina Pasat: Continuous everything for iOS apps
realm
0
670
Other Decks in Technology
See All in Technology
つくって納得、つかって実感! 大規模言語モデルことはじめ ver2.0
recruitengineers
PRO
4
1.7k
事業価値と Engineering 2026年度版
recruitengineers
PRO
50
24k
Sansan Engineering Unit 紹介資料
sansan33
PRO
1
4.9k
Agent 時代の Kaggle 展望 / kaggle-in-the-agentic-era
upura
1
760
サイバー捜査員研修(後半)
nomizone
1
880
Bits AI を制するものは Datadog を制す / The player that controls Bits AI, controls Datadog
kaminashi
0
110
ボトムアップ文化が強い組織で セキュリティをどう根付かせていくかの現在進行形の話 / Making Security Stick in a Bottom-Up Organization
yamaguchitk333
0
230
My broken English still works: speaking at global OSS events
naruoga
0
100
グローバル基準のSREは、運用現場でどう機能したか:成熟度アセスメントの実践 / SRE NEXT 2026
sorawatanabe
0
250
取引先から届く 「セキュリティチェックシート」の読み解き方
kamadamakoto
0
150
【AG-UI × A2UI × MCP Apps】Generative UIをやさしく解説する
nrinetcom
PRO
1
130
20分でわかるセキュアAPI
nwiizo
2
280
Featured
See All Featured
Technical Leadership for Architectural Decision Making
baasie
3
480
Fashionably flexible responsive web design (full day workshop)
malarkey
408
67k
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
Ethics towards AI in product and experience design
skipperchong
2
340
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
650
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.8k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
23k
Making Projects Easy
brettharned
120
6.7k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
3k
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
2.1k
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
210
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
340
Transcript
1
BUENOS DÍAS BARCELONA !☀# 2
FRP && TESTING 3
But before we start... 4
SMALL STORY... ! 5
WAY BACK IN 2013... ⏰ 6
FRP + RAC + OBJC ! 7
8
9
10
11
12
13
FRP 101 ! 14
FAMILIAR CONCEPTS... ! 15
KVO + NSOperation + ✨ 16
KVO 17
MutableProperty<T> 18
let foo = MutableProperty(1) // 1. observe foo foo.signalProducer.startWithNext {
newFooValue in print(newFooValue) // prints "1" } // 2. modifiy foo's value foo.value = 2 // 3. prints "2" 19
NSOperation 20
SignalProducer<T, E: ErrorType> 21
let networkCall: SignalProducer<NSData, NSError> = ... let parser: NSData ->
[Painting] = ... let paintingsProducer = networkCall.map(parser) .startOn(QueueScheduler()) 22
paintingsProducer.startWithNext { paintings in print(paintings) // [!, "] } paintingsProducer.on(
failure: { error in // handle error }, next: { paintings in print(paintings) // [!, "] }) .start() 23
✨ 24
25
EXAMPLES... ! 26
Form Validation 27
28
let email: MutableProperty<String> = emailTextField.rex_text let password: MutableProperty<String> = passwordTextField.rex_text
let isValid: (String, String) -> Bool = ... let areCredentialsValid = combineLatest(email.producer, password.producer).map(isValid) loginButton.rex_enabled <~ areCredentialsValid 29
30
Puzzle ! 31
32
33
A plan... ! 34
35
let drinks = SignalProducer<[String], NoError>(value: ["!","!"]) let areSober: [String] ->
Bool = ... let gamePlan = drinks .concat(drinks.delay(7.5)) .concat(timer(5).flatMapLatest { _ in drinks }.takeWhile(areSober)) 36
TESTING FRP ! 37
Discrete 38
func testNumberPaintings() { let expectation = self.expectationWithDescription("Expect to have 2
paintings") defer { self.waitForExpectationsWithTimeout(1.0, handler: nil) } paintingsViewModel.paintingsProducer.startWithNext { paintings in XCTAssertEqual(paintings.count, 2) expectation.fulfill() } } 39
func testNumberPaintings() { let result: Result<[Painting], Error>? = paintingsViewModel.paintingsProducer.first() XCTAssertEqual(result?.value?.count,
2) } 40
Continuous 41
final class StubbedNextValues<T: Equatable> { private var nextValues: [T] private
let expectation: XCTestExpectation init(nextValues: [T] , expectation: XCTestExpectation) { self.nextValues = nextValues self.expectation = expectation } func handleNextValue(nextValue: T) -> Void { guard !nextValues.isEmpty else { fatalError("Can't handle \(nextValue)") } let stubbedValue = nextValues.removeFirst() XCTAssertEqual(stubbedValue, nextValue) if nextValues.isEmpty { expectation.fulfill() } } } 42
let producer: SignalProducer<Int, NoError> = ... let stubbedNextValues = StubbedNextValues(nextValues:
[1, 2, 3, 4], expectation: expectation) producer.startWithNext(stubbed.handleNextValue) 43
FRP takes a while to get used to... ! 44
...testing FRP code is as difficult as you want it
to be ! 45
THANKS @peres 46
47