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
750
WebエンジニアのためのMySQLデータ構造基礎(再) / mysql data structure for web developer 2
mihyaeru21
0
260
WebエンジニアのためのMySQLデータ構造基礎 / mysql data structure for web developer
mihyaeru21
1
630
WebエンジニアのためのMySQL入門 / learning mysql for web developer
mihyaeru21
7
2.6k
RxSwiftと愉快な仲間たち / RxSwift with Units
mihyaeru21
4
2.7k
RxSwiftでTwitterの ライブラリを作ってる話 / RxTwift
mihyaeru21
4
710
CrystalでTwitter botを作ってみた / Create a Twitter bot in Crystal
mihyaeru21
0
1.3k
Gotanda.pm #1
mihyaeru21
1
150
Other Decks in Technology
See All in Technology
ドメインの本質を掴む / Get the essence of the domain
sinsoku
2
160
SRE×AIOpsを始めよう!GuardDutyによるお手軽脅威検出
amixedcolor
0
170
第1回 国土交通省 データコンペ参加者向け勉強会③- Snowflake x estie編 -
estie
0
130
AWS Media Services 最新サービスアップデート 2024
eijikominami
0
200
プロダクト活用度で見えた真実 ホリゾンタルSaaSでの顧客解像度の高め方
tadaken3
0
180
CysharpのOSS群から見るModern C#の現在地
neuecc
2
3.5k
Python(PYNQ)がテーマのAMD主催のFPGAコンテストに参加してきた
iotengineer22
0
500
The Role of Developer Relations in AI Product Success.
giftojabu1
0
140
EventHub Startup CTO of the year 2024 ピッチ資料
eventhub
0
120
マルチモーダル / AI Agent / LLMOps 3つの技術トレンドで理解するLLMの今後の展望
hirosatogamo
37
12k
【Pycon mini 東海 2024】Google Colaboratoryで試すVLM
kazuhitotakahashi
2
540
Lexical Analysis
shigashiyama
1
150
Featured
See All Featured
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
The Cost Of JavaScript in 2023
addyosmani
45
6.8k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.2k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
6.9k
Become a Pro
speakerdeck
PRO
25
5k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
4
370
For a Future-Friendly Web
brad_frost
175
9.4k
Faster Mobile Websites
deanohume
305
30k
Git: the NoSQL Database
bkeepers
PRO
427
64k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
28
2k
GraphQLの誤解/rethinking-graphql
sonatard
67
10k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
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ͰεοΩϦ