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
23k
Railsで実装されている機能のマイクロサービスへの切り離し / split to microservices from rails
mihyaeru21
1
740
WebエンジニアのためのMySQLデータ構造基礎(再) / mysql data structure for web developer 2
mihyaeru21
0
250
WebエンジニアのためのMySQLデータ構造基礎 / mysql data structure for web developer
mihyaeru21
1
620
WebエンジニアのためのMySQL入門 / learning mysql for web developer
mihyaeru21
7
2.5k
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
令和最新版 Perlコーディングガイド
anatofuz
4
3.5k
How CERN serves 1EB of data via FUSE
ennael
PRO
0
16k
O'Reilly Superstream: Building a RAG App to Chat with Your Data
pamelafox
0
120
入門 KRR
donkomura
0
110
スモールスタート、不都合な真実 〜 耳当たりの良い言葉に現場が振り回されないために/20240930-ssmjp-small-start
opelab
13
1.8k
Pythonを活用したLLMによる構造的データ生成の手法と実践
brainpadpr
3
320
AI時代のアジャイル開発(XP祭り2024版) / Agile Development in the AI Era in XPJUG
takaking22
13
3.6k
【swonet.conf_】NOCメンバーが語るSTMの実態!! ~ShowNetから若者への贈り物~
shownet
PRO
0
300
成果のためのコミュニケーション - 語彙を育てよう -/communication-for-good-outcome-developing-vocabulary
hassaku63
4
160
Assisted reorganization of data structures
ennael
PRO
0
250
AWSへのNIST SP800-171管理策 導入に向けての整備/20240930 Mitsutoshi Matsuo
shift_evolve
0
200
業務ヒアリングと知識の呪い
tamai_63
0
280
Featured
See All Featured
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
225
22k
Code Reviewing Like a Champion
maltzj
519
39k
Git: the NoSQL Database
bkeepers
PRO
425
64k
The Invisible Customer
myddelton
119
13k
ParisWeb 2013: Learning to Love: Crash Course in Emotional UX Design
dotmariusz
110
6.9k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
327
21k
A better future with KSS
kneath
237
17k
Building Adaptive Systems
keathley
38
2.1k
The Cult of Friendly URLs
andyhume
77
6k
Keith and Marios Guide to Fast Websites
keithpitt
408
22k
Pencils Down: Stop Designing & Start Developing
hursman
119
11k
Become a Pro
speakerdeck
PRO
24
4.9k
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ͰεοΩϦ