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
420
入門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
760
WebエンジニアのためのMySQLデータ構造基礎(再) / mysql data structure for web developer 2
mihyaeru21
0
260
WebエンジニアのためのMySQLデータ構造基礎 / mysql data structure for web developer
mihyaeru21
1
640
WebエンジニアのためのMySQL入門 / learning mysql for web developer
mihyaeru21
7
2.6k
RxSwiftと愉快な仲間たち / RxSwift with Units
mihyaeru21
4
2.7k
RxSwiftでTwitterの ライブラリを作ってる話 / RxTwift
mihyaeru21
4
720
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
ゼロから創る横断SREチーム 挑戦と進化の軌跡
rvirus0817
2
270
マルチプロダクト開発の現場でAWS Security Hubを1年以上運用して得た教訓
muziyoshiz
3
2.4k
re:Invent 2024 Innovation Talks(NET201)で語られた大切なこと
shotashiratori
0
310
ブラックフライデーで購入したPixel9で、Gemini Nanoを動かしてみた
marchin1989
1
540
[Ruby] Develop a Morse Code Learning Gem & Beep from Strings
oguressive
1
170
2024年にチャレンジしたことを振り返るぞ
mitchan
0
140
開発生産性向上! 育成を「改善」と捉えるエンジニア育成戦略
shoota
2
390
Turing × atmaCup #18 - 1st Place Solution
hakubishin3
0
490
社内イベント管理システムを1週間でAKSからACAに移行した話し
shingo_kawahara
0
190
祝!Iceberg祭開幕!re:Invent 2024データレイク関連アップデート10分総ざらい
kniino
3
310
組織に自動テストを書く文化を根付かせる戦略(2024冬版) / Building Automated Test Culture 2024 Winter Edition
twada
PRO
17
4.6k
私なりのAIのご紹介 [2024年版]
qt_luigi
1
120
Featured
See All Featured
Thoughts on Productivity
jonyablonski
67
4.4k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
[RailsConf 2023] Rails as a piece of cake
palkan
53
5k
How to train your dragon (web standard)
notwaldorf
88
5.7k
Facilitating Awesome Meetings
lara
50
6.1k
How GitHub (no longer) Works
holman
311
140k
Java REST API Framework Comparison - PWX 2021
mraible
28
8.3k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Navigating Team Friction
lara
183
15k
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
A Philosophy of Restraint
colly
203
16k
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ͰεοΩϦ