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
RxJava初心者の私が良いと思ったやり方、素敵だと思った資料など
Search
RyotaMurohoshi
October 28, 2014
Technology
0
13
RxJava初心者の私が良いと思ったやり方、素敵だと思った資料など
2014/10/28にpixivさんで行われたRxJavaNightの@RyotaMurohoshiの資料です。
※元々はSlideShareで公開していた資料です
RyotaMurohoshi
October 28, 2014
Tweet
Share
More Decks by RyotaMurohoshi
See All by RyotaMurohoshi
Unityの合同同人誌や合同商業誌を書いてる僕は感想やレビューや評価が欲しい
ryotamurohoshi
0
370
Unity 2021.1での Unityパッケージの名称変更について
ryotamurohoshi
0
630
Odin Validationはいいぞ!
ryotamurohoshi
2
860
Tilemapはいいぞ!2020 〜すごいぞ、プロジェクト専用拡張Brush〜
ryotamurohoshi
0
2.3k
Unityでも、新しいC#
ryotamurohoshi
0
1.2k
Riderはいいぞ!
ryotamurohoshi
1
3.2k
Riderのススメ〜俺はRiderここが好き〜
ryotamurohoshi
1
2.2k
Unity開発者に伝えたい.NETのこと
ryotamurohoshi
4
36k
ImportedLinqのススメ
ryotamurohoshi
0
1.3k
Other Decks in Technology
See All in Technology
誰も全体を知らない ~ ロールの垣根を超えて引き上げる開発生産性 / Boosting Development Productivity Across Roles
kakehashi
1
230
Taming you application's environments
salaboy
0
190
Flutterによる 効率的なAndroid・iOS・Webアプリケーション開発の事例
recruitengineers
PRO
0
110
TanStack Routerに移行するのかい しないのかい、どっちなんだい! / Are you going to migrate to TanStack Router or not? Which one is it?
kaminashi
0
600
AGIについてChatGPTに聞いてみた
blueb
0
130
OCI Network Firewall 概要
oracle4engineer
PRO
0
4.1k
Exadata Database Service on Dedicated Infrastructure(ExaDB-D) UI スクリーン・キャプチャ集
oracle4engineer
PRO
2
3.2k
Terraform Stacks入門 #HashiTalks
msato
0
360
エンジニア人生の拡張性を高める 「探索型キャリア設計」の提案
tenshoku_draft
1
130
SRE×AIOpsを始めよう!GuardDutyによるお手軽脅威検出
amixedcolor
0
130
New Relicを活用したSREの最初のステップ / NRUG OKINAWA VOL.3
isaoshimizu
2
610
適材適所の技術選定 〜GraphQL・REST API・tRPC〜 / Optimal Technology Selection
kakehashi
1
660
Featured
See All Featured
BBQ
matthewcrist
85
9.3k
Mobile First: as difficult as doing things right
swwweet
222
8.9k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
26
2.1k
For a Future-Friendly Web
brad_frost
175
9.4k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
890
The Art of Programming - Codeland 2020
erikaheidi
52
13k
Intergalactic Javascript Robots from Outer Space
tanoku
269
27k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
1.9k
How To Stay Up To Date on Web Technology
chriscoyier
788
250k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
229
52k
How STYLIGHT went responsive
nonsquared
95
5.2k
A Tale of Four Properties
chriscoyier
156
23k
Transcript
@RyotaMurohoshi 2014/10/28'RxJava'Night
೦ͳ͕Βɺॳ৺ऀͰ͢ ͝ΊΜͳ͍͞
ಥવͰ͕࣭͢Ͱ͢ʂ
RxJavaͳͲΛ͏͢Ͱʹ ΨοπϦ͍ͬͯΔํʁ
RxJavaɺHello*world ͨ͠Αͬͯํʁ
RxJavaΑ͘Θ͔Βͳ͍͚Ͳ ڵຯ͋ΔΑͬͯํʁ
ϓϩάϥϛϯάݴޠGroovy ͍ͬͯΔ!or!͍ͬͯΔํʁ
C#erͳํɺC#͔Δํʁ
Unity͍ͬͯΔํʁ
͋Γ͕ͱ͏͍͟͝·ͨ͠
͓લͩΕΑ • ໊લ":"྄ࣨଠ • ࣄ":"UnityήʔϜ։ൃ(C#)ɺʲલʳAndroidΞϓϦ։ൃ(Java) • Twi6er":"@RyotaMurohoshi • ߘઌ":"h6p:/ /qiita.com/RyotaMurohoshi
• ڵຯ":"UnityɺC#ɺGroovy
ʲॳ৺ऀ͕ͬͯΈͨʳ RxɺνϟϨϯδͯ͠Έͨ ͱ͍͏ςʔϚͰɺ಄ͷ࣭ʹؔͷ͋Δ༰Ͱ͓ૹΓ͠·͢ɻ
ձ͕ʮRx͍͢͝ਓͨͪʯ͔ΓͩͬͨΒ ΨνযΓ͍ͯ͠·͢ ੜஆ͔͍Ͱݟ͍ͯ͋͛ͯͩ͘͞
Έͳ͞ΜRxJavaΛΓ·ͨ͠ɻ ͬͯΈ͍ͨͰ͢Ͷɻ ·ͣɺͲ͜Λݟ·͔͢ʁ
RxJavaͷwiki h"ps:/ /github.com/Reac3veX/RxJava/wiki
RxJavaͷWiki)filterϝιουͷઆ໌ΑΓ h0ps:/ /github.com/Reac<veX/RxJava/wiki/FilteringAObservables) numbers = Observable.from([1, 2, 3, 4, 5,
6, 7, 8, 9]); numbers.filter({ 0 == (it % 2) }).subscribe( { println(it); }, // onNext { println("Error: " + it.getMessage()); }, // onError { println("Sequence complete"); } // onCompleted );
Μʁ
ͳΜͩ͜Εʁ • [1,%2,%3,%4,%5,%6,%7,%8,%9] • {%0%==%(it%%%2)%} • it • println%("Sequence%Complete")
Groovy
ʲΑ͍ͱ͓ͬͨɺίϨศརʂʳ RxJava͏ͳΒɺGroovy͋Γʂ
RxJavaͷwikiͷαϯϓϧίʔυɺ ݁ߏGroovyͰॻ͔Ε͍ͯΔ
Groovy • JVMݴޠ • Javaͱͷੑ͕ߴ͍ • ؆ܿͳهड़ॊೈͳॲཧ͕Ͱ͖Δ • Groovy2.4͔ΒAndroidʹରԠ(ࠓbeta63)
RxJavaɺΠϯλʔϑΣʔεΛҾʹͱΔϝιου͔ΓͰ͢Ͷ .map(new Func1<OnClickEvent, Integer>() { @Override public Integer call(OnClickEvent clickEvent)
{ return 1; } }) ແବʹ͍ɽɽɽ
ແବʹ͍ͷݏͩʂ • Java8ͳΒϥϜμࣜ • Java8ΑΓલͰretrolambda
ແବʹ͍ͷݏͩʂ • Java8ͳΒϥϜμࣜ • Java8ΑΓલͰretrolambda • Groovy͋Γʂ
Androidͩͱɺ
RxAndroidͱRxJavaɺBu.onΫϦοΫճΛTextViewʹදࣔ ViewObservable.clicks(findViewById(R.id.button)) .map(new Func1<OnClickEvent, Integer>() { @Override public Integer call(OnClickEvent
clickEvent) { return 1; } }) .scan(new Func2<Integer, Integer, Integer>() { @Override public Integer call(Integer acc, Integer current) { return acc + current; } }) .subscribe(new Action1<Integer>() { @Override public void call(Integer clickCount) { TextView textView = (TextView)findViewById(R.id.text_view); textView.setText(clickCount.toString()); } });
͍ʂ
RxAndroidͱRxJavaͱGroovyɺBu0onΫϦοΫճΛTextViewʹදࣔ ViewObservable.clicks(findViewById(R.id.button)) .map { 1 } .scan { acc, current
-> acc + current } .subscribe { findViewById(R.id.text_view).setText(it.toString()) }
͖ͬ͢Γʂ
GroovyͷΫϩʔδϟͰɺͱ͖ͬͯͬ͢Γʂ RxAndroid+Groovyͷྫ-h/p:/ /qiita.com/RyotaMurohoshi/items/48bbbecea49591fd20a2 Ϋϩʔδϟͷॻ͖ํ͍Ζ͍Ζ!h#p:/ /qiita.com/RyotaMurohoshi/items/2a30a74c0074e11d0207
RxGroovy • RxJavaͷΠϯλʔϑΣʔεΛҾʹͱΔϝιουͰɺGroovyͷ ΫϩʔδϟΛͤΔΑ͏ʹ͢Δͷ • Groovy2.2Ҏ্ͳΒΫϩʔδϟͷ҉తͳڧ੍ܕมʹΑΓɺ RxGroovyͳ͠ͰΫϩʔδϟΛͤΔ • AndroidͰGroovy2.4Ҏ্͏ͳΒɺRxGroovyແͯ͘OK h"p:/
/qiita.com/RyotaMurohoshi/items/3f1f3cde0e5c6785b2f1
GroovyͰɺRxJava͜Μͳ͍هड़Ͱ࢝ΊΒΕΔ @Grab(group='com.netflix.rxjava', module='rxjava-core', version='0.20.4') import rx.Observable import rx.functions.Action1 Observable.from("Taro", "Jiro",
"Saburo").subscribe { println "Hello $it"}
RxJavaʹݶΒͣɺJavaͷϥΠϒϥϦΛνϣϩͬͱࢼ࣌͢ Groovyศརͩͱࢥ͍·͢ʂ • Ϋϥεͱ͔mainϝιουͳ͠Ͱ͍͖ͳΓॻ͚Δ(εΫϦϓτ) • GrapeʹΑΓɺΞϊςʔγϣϯҰൃͰϥΠϒϥϦ͑Δ • GroovyShellͰରతʹࢼͤΔ h"p:/ /qiita.com/RyotaMurohoshi/items/99475255e56f8fae712b
ʲΑ͍ͱ͓ͬͨɺίϨศརʂʳ RxJava͏ͳΒɺGroovy͋Γʂ Ͱͨ͠ʂ
ͯ͞ɺRxJava͍͜ͳͤΔΑ͏ʹͳΓ͍ͨͰ͢ΑͶʁ Ͳ͏͠·͠ΐ͏ʁ
RxJava&is&a&Java&VM&implementa1on& of&Reac1ve&Extensions:&a&library&for& composing&asynchronous&and&event> based&programs&by&using&observable& sequences. —"RxJavaͷwiki"HomeΑΓ(h1ps://github.com/Reac<veX/RxJava/wiki)
Reac%ve'Extensions
RxJavaReac(ve)Extensions(C#ͷϥΠϒϥϦ)Λجʹ͍ͯ͠Δ RxJavaΛ͍͜ͳ͍ͨ͠ͳΒ Reac%ve'ExtensionsͷهࣄɾߘͳͲͷใཱͭʂ
ʲ͜ͷใ͕ૉఢʂͱ͔ͬͯΓ͍͢ʂʳ Reac%ve'ExtensionsͷࢿྉͰRxͷษڧΛ͠ɺ RxJavaΛ͍͜ͳ͢
ͪΖΜJavaͱC#ͷҧ͍͋Γ·͢ ϝιου໊͕ҧ͏ͭ͋Γ·͢(WhereͱfilterɺSelectͱmap)
ͦΕͰRxͷߟ͑ํΛ ཧղ͢Δͷʹɺ ͱ͍͍ͬͯͱࢥ͍·͢ʂ
ϓϩάϥϛϯάC#ୈ7൛ 11ষؙʑRx(Reac(ve*Extensions) ͝ΊΜͳ͍͞ɺ࠷ॳʹ͜ΕಡΉͷͪΐͬͱͭΒ͔ͬͨͰ͢
Reac%ve'Extensions(C#ͷϥΠϒϥϦ)ͷ ૉఢͳϒϩάɾهࣄΛߘ͞Ε͍ͯΔํୡ͕͍·͢ ͦͷํୡͷϒϩάͱ͔ͯΓ͔ͬͨ͢Ͱ͢
xin9le͞Μ Rxೖ h"p:/ /xin9le.net/rx/intro
xin9le͞ΜͷRxೖ RxͷೖɻϓϩάϥϛϯάC#%ୈ7൛ΛಡΉલʹɺͪ͜ΒΛઌʹಡΈ͔ͨͬͨɻ ॳΊʹͪ͜ΒΛಡΉͷ͕ͱ͍͍ͯͱࢥ͍·͢ʂ ଞʹεϥΠυͨ͘͞Μެ։͞Ε͍ͯ·͢ʂ
okazuki͞Μ Reac%ve'Extensions'࠶ೖ h"p:/ /okazuki.hatenablog.com/archive/category/Reac9ve%20Extensions
okazuki͞ΜͷReac*ve,Extensions࠶ೖ Reac%ve'ExtensionsͷϝιουΛ࣮ࡍʹಈ͔ͨ͠αϯϓϧίʔυ͕ͨ͘͞Μ ϦϑΝϨϯεͷઆ໌จΛݟͯϝιουͷΠϝʔδ͕༙͖·ͤΜͰ͕ͨ͠ɺ ࣮ࡍͷίʔυͱ࣮ߦ݁ՌͰΠϝʔδ͕༙͖·ͨ͠ʂ
neuecc͞Μ ࿈ࡌɿReac%ve'ExtensionsʢRxʣೖ h"p:/ /www.atmarkit.co.jp/fdotnet/introrx/index/ UniRxʹ͍ͭͯ h"p:/ /neue.cc/2014/08/23_476.html7ͳͲ
neuecc͞Μ ͔ͳΓૣ͍ஈ֊͔ΒReac%ve'Extensionsʹ͞Ε͍ͯͯ·͢ ϒϩάɺεϥΠυ͚ͩͰͳ͘@IT͞ΜͰ࿈ࡌ͞Ε͍ͯ·͢ UnityͰ͑ΔReac*ve,ExtensionsҠ২ͷUniRxͷ࡞ऀ͞ΜͰ͢ ࠓొஃ͞Ε͍ͯ·͢
ʲ͜ͷใ͕ૉఢʂͱ͔ͬͯΓ͍͢ʂʳ Reac%ve'ExtensionsͷࢿྉͰRxͷษڧΛ͠ɺ RxJavaΛ͍͜ͳ͢ Ͱͨ͠ʂ
γϯϓϧͳྫͰ͕͢ɺ ·ͣखΛಈ͔ͯ͠Έ·ͨ͠ʂ ࠓޙͬͯΈͯɺߘ͍ͯ͜͠͏ͱࢥ͍·͢ ؒҧ͍ͬͯͨΒɺ༏͘͠·͔͞Γ͍͚͛ͯͨͩΔͱ͏Ε͍͠Ͱ͢ RxAndroid+Groovy-:ɹh0p:/ /qiita.com/RyotaMurohoshi/items/48bbbecea49591fd20a2 UnityͰUniRxΛͬͯ(:(h+p:/ /qiita.com/RyotaMurohoshi/items/7e1509e03d8e3a1eae4f
ল ཧతͳجૅͷษڧΛޙճ͠ʹ͗ͯ͢͠͠·ͬͨɻ
FRPRxʹ͍ͭͯ ·ͬͨ͘;Εͣਃ͠༁ͳ͍Ͱ͢ʂ
ʲॳ৺ऀ͚ͩΕͲʳ RxɺGroovyͰࢼ͢ͷ͋Γͩͱࢥ͏͠ɺ Reac%ve'Extensinsͷࢿྉ ͱͬͯࢀߟʹͳΔͱࢥ͏ɻ Ͱͨ͠ɻ
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ɻ @RyotaMurohoshi h"p:/ /qiita.com/RyotaMurohoshi