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
入門ReactiveX / about ReactiveX
Search
Mihyaeru
June 27, 2016
Technology
3
430
入門ReactiveX / about ReactiveX
Mihyaeru
June 27, 2016
Tweet
Share
More Decks by Mihyaeru
See All by Mihyaeru
会計 freee バックエンドの今後 / freee backend api
mihyaeru21
8
24k
Railsで実装されている機能のマイクロサービスへの切り離し / split to microservices from rails
mihyaeru21
1
790
WebエンジニアのためのMySQLデータ構造基礎(再) / mysql data structure for web developer 2
mihyaeru21
0
270
WebエンジニアのためのMySQLデータ構造基礎 / mysql data structure for web developer
mihyaeru21
1
650
WebエンジニアのためのMySQL入門 / learning mysql for web developer
mihyaeru21
7
2.6k
RxSwiftと愉快な仲間たち / RxSwift with Units
mihyaeru21
4
2.7k
RxSwiftでTwitterの ライブラリを作ってる話 / RxTwift
mihyaeru21
4
730
CrystalでTwitter botを作ってみた / Create a Twitter bot in Crystal
mihyaeru21
0
1.3k
Gotanda.pm #1
mihyaeru21
1
160
Other Decks in Technology
See All in Technology
Apache Iceberg Case Study in LY Corporation
lycorptech_jp
PRO
0
350
Pwned Labsのすゝめ
ken5scal
2
520
あなたが人生で成功するための5つの普遍的法則 #jawsug #jawsdays2025 / 20250301 HEROZ
yoshidashingo
2
320
Oracle Database Technology Night #87-1 : Exadata Database Service on Exascale Infrastructure(ExaDB-XS)サービス詳細
oracle4engineer
PRO
1
210
手を動かしてレベルアップしよう!
maruto
0
240
サイト信頼性エンジニアリングとAmazon Web Services / SRE and AWS
ymotongpoo
7
1.7k
開発者のための FinOps/FinOps for Engineers
oracle4engineer
PRO
2
210
1行のコードから社会課題の解決へ: EMの探究、事業・技術・組織を紡ぐ実践知 / EM Conf 2025
9ma3r
12
4.4k
役員・マネージャー・著者・エンジニアそれぞれの立場から見たAWS認定資格
nrinetcom
PRO
4
6.5k
"TEAM"を導入したら最高のエンジニア"Team"を実現できた / Deploying "TEAM" and Building the Best Engineering "Team"
yuj1osm
1
230
AI Agent時代なのでAWSのLLMs.txtが欲しい!
watany
3
340
DevinでAI AWSエンジニア製造計画 序章 〜CDKを添えて〜/devin-load-to-aws-engineer
tomoki10
0
190
Featured
See All Featured
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
How to train your dragon (web standard)
notwaldorf
91
5.9k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.2k
Testing 201, or: Great Expectations
jmmastey
42
7.2k
Gamification - CAS2011
davidbonilla
80
5.2k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
227
22k
Why You Should Never Use an ORM
jnunemaker
PRO
55
9.2k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
3.7k
Faster Mobile Websites
deanohume
306
31k
Build The Right Thing And Hit Your Dates
maggiecrowley
34
2.5k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
120k
The Power of CSS Pseudo Elements
geoffreycrofte
75
5.5k
Transcript
ೖ 3FBDUJWF9 /%4 PO @mihyaeru21 ஶ ϛώϟΤϧ༁ A library for
composing asynchronous and event-based programs by using observable sequences. ͟ ͬ ͘ Γ ൛
දࢴग़མͪ ※දࢴͷςΩετͱΞΠίϯ http://reactivex.io/ ΑΓ
ࣗݾհ w ϛώϟΤϧ!NJIZBFSV w ʮ3Y͍͍ͧʯ w ʮ4XJGU͍͍ͧʯ w ʮ,PUMJO͍͍ͧʯ
w Φϥ˓Ϧʔͷճ͠ऀͰͳ͍
3FBDUJWF9 w ུͯ͠3Y w IUUQSFBDUJWFYJP w 0CTFSWFSύλʔϯͷ֦ு w ͋ͳ͕ͨٻΊ͍ͯͨϦΞΫςΟϒϓϩάϥϛϯάೖ w
IUUQOJOKJOLVOIBUFOBCMPHDPNFOUSZJOUSPSYKB
Կ͕ྑ͍ʁ w ඇಉظॲཧΛྑ͍ײ͡ʹॻ͚Δ w ଟ͘ͷݴޠͰ࣮͞Ε͓ͯΓ൚༻తʹ͑Δ w υΩϡϝϯτ͕ʢଞݴޠ൛ΛؚΊΕʣ๛ w એݴతʹϓϩάϥϛϯάͰ͖Δ
ࠓ֮͑ͯ΄͍͜͠ͱ
Observable<T>
ཱͪҐஔ ճ ෳճ ಉظ T getData() Iterable<T> getData() ඇಉظ
Future<T> getData() Observable<T> getData() from http://reactivex.io/intro.html
0CTFSWBCMF w ΠϕϯτετϦʔϜ w छྨͷΠϕϯτ͕ྲྀΕͯ͘Δ w /FYU w &SSPS w
$PNQMFUF w ଟͷΦϖϨʔλʹΑΔॊೈੑ
ࢁ΄Ͳ͋ΔΦϖϨʔλ from http://reactivex.io/documentation/operators.html
ετϦʔϜ from http://rxmarbles.com/ ͜ͷҹʴϚʔϒϧ͕ͭͷ0CTFSWBCMF ͜ͷਤϚʔϒϧμΠΞάϥϜͱ͍͏
ετϦʔϜ from http://rxmarbles.com/ /FYUΠϕϯτ
ετϦʔϜ from http://rxmarbles.com/ $PNQMFUFΠϕϯτ
NBQετϦʔϜͷม from http://rxmarbles.com/ ͬͪ͜ม͞Εͨ0CTFSWBCMF
ΤϥʔΛѻ͏ྫ &SSPSΠϕϯτ from http://reactivex.io/documentation/operators/catch.html
ΤϥʔΛѻ͏ྫ from http://reactivex.io/documentation/operators/catch.html ΤϥʔΛѲΓͭͿͯ͠ɺࢦఆͨ͠Λྲྀ͢
3Y4XJGUͰͷදݱ let anotherStream = stream .catchErrorJustReturn(0) .map { $0
* 10 }
3Y.BSCMFT ಈ͔͠ͳ͕ΒࢼͤΔ
มΘ͔ͬͨ
ΠϕϯτΛर͏ʹʁ
subscribe
TVCTDSJCF w ߪಡ͢Δ w ֤ΠϕϯτʹରԠͨ͠ίʔϧόοΫΛࢦఆ͢Δ w ؔ w 0CTFSWFS5
TVCTDSJCF stream.catchErrorJustReturn(0) .map { $0 * 10 } .subscribe(
onNext: { value in print("onNext: \(value)") }, onError: { error in // この例ではエラーは流れてこない print("onError: \(error)") }, onCompleted: { print("onCompleted") } )
TVCTDSJCF w 0CTFSWBCMFTVCTDSJCFͨ͠ॠؒʹൃՐ͢Δ w "1*Λୟ͘Α͏ͳ0CTFSWBCMFͩͬͨ߹ɺ 0CTFSWBCMFͷΠϯελϯεΛ࡞ͬͨ࣌Ͱ ࣮ࡍͷಈ࡞Կߦ͍ͬͯͳ͍ w ʢ࣮ࡍʹɺTVCTDSJCF͠ͳͯ͘Πϕϯτ͕ਨΕྲྀ͞ΕΔ)PUͳ0CTFSWBCMFͱɺ ͦ͏Ͱͳ͍$PMEͳ0CTFSWBCMF͕͋Δ͕ࠓճׂѪ͢Δɻ͜ͷهࣄ͕ৄ͍͠
IUUQRJJUBDPNUP3JTPV1JUFNTGCGEBEʣ
0CTFSWBCMFࡶ·ͱΊ w Λෳྲྀͤͯ w ศརͳίϨΫγϣϯૢ࡞͕͍Ζ͍ΖͰ͖Δ w 1SPNJTF
ͪΐͬͱͬͯ
ίʔϧόοΫࠈʹ ͳΓͦ͏͡Όͳ͍ʁ
ඇಉظͷஞ࣮࣍ߦ fetchHoge().subscribeNext { res in fetchFuga(id: res.id).subscribeNext { res2
in fetchPiyo(key: res2.key).subscribeNext { res3 in // do something with res3... } } } TVCTDSJCF/FYUɺ/FYUΠϕϯτ͚ͩTVCTDSJCF͢Δͭ
ݟࣄʹίʔϧόοΫࠈ ʗ ?P? ʘ
qBU.BQ fetchHoge() .flatMap { fetchFuga(id: $0.id) } .flatMap {
fetchPiyo(key: $0.key) } .subscribeNext { res in // do something with res... }
qBU.BQ w NBQʹࣅ͍ͯΔ w ੜͷͰͳ͘ɺผͷ0CTFSWBCMFʹม͢Δ w ݩͷετϦʔϜ͔ΒͷΠϕϯτͷλΠϛϯάͰɺ ผͷετϦʔϜ͕ൃՐͯ͠ɺͦͷΠϕϯτ͕ྲྀΕΔ w TVCTDSJCFͷதͰTVCTDSJCFͨ͘͠ͳͬͨΒ
qBU.BQͷग़൪Ͱ͋ΔՄೳੑ͕ඇৗʹߴ͍
·ͱΊ w 3Y0CTFSWBCMFΛத৺ͱͨ͠ ඇಉظετϦʔϜϥΠϒϥϦ w 0CTFSWBCMFͷΠϕϯτΛड͚औΔʹTVCTDSJCF w ͨ͘͞Μ͋ΔΦϖϨʔλͰॊೈͳهड़͕Ͱ͖Δ w ஞ࣮࣍ߦqBU.BQͰεοΩϦ