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
770
WebエンジニアのためのMySQLデータ構造基礎(再) / mysql data structure for web developer 2
mihyaeru21
0
270
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
メンタル面でもつよつよエンジニアになる/登壇資料(井田 献一朗)
hacobu
0
150
Opcodeを読んでいたら何故かphp-srcを読んでいた話
murashotaro
0
350
ゼロから創る横断SREチーム 挑戦と進化の軌跡
rvirus0817
3
650
「完全に理解したTalk」完全に理解した
segavvy
1
210
Unlearn Product Development - Unleashed Edition
lemiorhan
PRO
2
150
Working as a Server-side Engineer at LY Corporation
lycorp_recruit_jp
0
460
10年もののバグを退治した話
n_seki
0
110
TSKaigi 2024 の登壇から広がったコミュニティ活動について
tsukuha
0
170
C++26 エラー性動作
faithandbrave
2
850
スケールし続ける事業とサービスを支える組織とアーキテクチャの生き残り戦略 / The survival strategy for Money Forward’s engineering.
moneyforward
0
140
React Routerで実現する型安全なSPAルーティング
sansantech
PRO
2
350
UI State設計とテスト方針
rmakiyama
4
890
Featured
See All Featured
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
830
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
Site-Speed That Sticks
csswizardry
2
200
Facilitating Awesome Meetings
lara
50
6.1k
Being A Developer After 40
akosma
89
590k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.2k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.3k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
6
470
The World Runs on Bad Software
bkeepers
PRO
66
11k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
26
1.9k
BBQ
matthewcrist
85
9.4k
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ͰεοΩϦ