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
怖くないReactive Extensions
Search
いも
December 12, 2017
Technology
0
620
怖くないReactive Extensions
社内の新卒向け座学の資料から社内情報を削ったりしたものです
いも
December 12, 2017
Tweet
Share
More Decks by いも
See All by いも
UnityプログラミングバイブルR6号宣伝&Unity Logging小話
adarapata
0
380
Unityテスト活動のふりかえり
adarapata
1
500
Gather.townはいいぞ その後
adarapata
1
1.5k
Unityでの開発事例
adarapata
3
22k
どこのご家庭にもあるシーンマネージャーの話
adarapata
1
7.3k
Gather.townはいいぞ
adarapata
2
2.3k
宴はいいぞ
adarapata
0
1.3k
わかった気になるモブプログラミング
adarapata
1
84
モブワークっぽいのをやっている話/Trying mobwork
adarapata
2
1.2k
Other Decks in Technology
See All in Technology
EventHub Startup CTO of the year 2024 ピッチ資料
eventhub
0
110
10XにおけるData Contractの導入について: Data Contract事例共有会
10xinc
6
620
Adopting Jetpack Compose in Your Existing Project - GDG DevFest Bangkok 2024
akexorcist
0
110
障害対応指揮の意思決定と情報共有における価値観 / Waroom Meetup #2
arthur1
5
470
初心者向けAWS Securityの勉強会mini Security-JAWSを9ヶ月ぐらい実施してきての近況
cmusudakeisuke
0
120
Incident Response Practices: Waroom's Features and Future Challenges
rrreeeyyy
0
160
透過型SMTPプロキシによる送信メールの可観測性向上: Update Edition / Improved observability of outgoing emails with transparent smtp proxy: Update edition
linyows
2
210
適材適所の技術選定 〜GraphQL・REST API・tRPC〜 / Optimal Technology Selection
kakehashi
1
170
リンクアンドモチベーション ソフトウェアエンジニア向け紹介資料 / Introduction to Link and Motivation for Software Engineers
lmi
4
300k
RubyのWebアプリケーションを50倍速くする方法 / How to Make a Ruby Web Application 50 Times Faster
hogelog
3
940
マルチプロダクトな開発組織で 「開発生産性」に向き合うために試みたこと / Improving Multi-Product Dev Productivity
sugamasao
1
300
The Role of Developer Relations in AI Product Success.
giftojabu1
0
120
Featured
See All Featured
Six Lessons from altMBA
skipperchong
27
3.5k
Practical Orchestrator
shlominoach
186
10k
10 Git Anti Patterns You Should be Aware of
lemiorhan
654
59k
How to Ace a Technical Interview
jacobian
276
23k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
720
Speed Design
sergeychernyshev
25
620
How To Stay Up To Date on Web Technology
chriscoyier
788
250k
How to train your dragon (web standard)
notwaldorf
88
5.7k
The Art of Programming - Codeland 2020
erikaheidi
52
13k
Designing on Purpose - Digital PM Summit 2013
jponch
115
7k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Measuring & Analyzing Core Web Vitals
bluesmoon
4
120
Transcript
ReactiveExtensions
Imoto Hiroto (2012~) (2013/1 ~ 2017/2) API minne (2017/3~) Android
Android https://adarapata.com/
None
ReactiveExtensions(Rx) Rx Rx Scheduler, Hot&Cold, Subject Reactive Streams RP, FRP,
Rx
User[] users = getUsers(); for(User user : users) { if
(user.getAge() >= 20) { String displayName = user.getName() + ":" user.getAge() System.out.println(displayName); } } Observable.fromArray(getUsers()) .filter(user -> user.getAge() >= 20) .map(user -> user.getName() + ":" user.getAge() + " ") .subscribe(name -> System.out.println(name));
getUserObservable() .map(response -> response.getBody()) .flatMap(user -> getFollowersObservable(user.getId())) .map(response -> response.getBody())
.subscribe(followersList -> { // }); getUserAsync(userResponse -> { User user = userResponse.getBody(); getFollowersAsync(user.getId(), followersResponse -> { List<User> followers = followersResponse.getBody(); // }) })
private Boolean isClicked = false; button.setOnClickListener(view -> { if(!isClicked) {
doSomething(); isClicked = true; } } RxView.clicks(button) .take(1) .subscribe(view -> doSomething());
None
Reactive Extensions(Rx) .NET Framework http://reactivex.io/ RxJava,RxJS,RxSwift etc... React.js
int a = 10; int b = a * 2;
a = 20; System.out.println(b); // => 40 https://www.slideshare.net/ytakano/ss-63454513
Rx LINQ .NET LINQ(Language Integrated Query) Objects, XML, MySQL etc..
http://www.atmarkit.co.jp/fdotnet/chushin/roadto linq_01/roadtolinq_01_01.html
LINQ (C#) List<User> users; // List<String> youngNames = users.Where(user =>
user.age < 20 .Select(user => user.name).ToList(); foreach(String n in youngNames) { // Console.WriteLine(n); }
LINQ LINQ Rx LINQ to Events, LINQ to Asynchronous Rx
LINQ Rx
before System.out.println("Hello World"); after Observable.just("Hello World") .subscribe(System::out::println);
before String hello = "Hello World"; System.out.println(hello.toUpperCase()); // HELLO WORLD
after Observable.just("Hello World") .map(toUpperCase) // .subscribe(System::out::println); // HELLO WORLD
before after String hello = "Hello World"; if(new Random().nextInt(10) <
3) { System.out.println(hello.toUpperCase()); // HELLO WORLD } Observable.just("Hello World") .filter(hello -> new Random().nextInt(10) < 3) .map(toUpperCase) // .subscribe(System::out::println); // HELLO WORLD
None
Rx --1---2---3---4--|--> Observable.just(1,2,3,4); // 1,2,3,4
OnNext OnError OnComplete = OnNext OnComplete ↓ ↓ just(1,2,3,4) --1--2--3--4--|-->
(Subscribe) Observable.just("Hello World") .subscribe(System::out::println); just("HelloWorld") ----H---|--> subscribe(println); "Hello World" println
Rx
2 20 just(10,20,30) ---10----11-----12----|--> map(data * 2) ---20----22-----24----|--> filter(data >
20) ---------22-----24----|--> Observable.just(10, 11, 12) // .map(data -> data * 2) // .filter(data -> data > 20)//
Rx
Rx
List<User> users = getUsers(); for(User user : users) { List<Tweet>
tweets = user.getTweets(); for(Tweet tweet : tweets) { System.out.println(tweet.getBody()); } }
List<User> users = getUsers(); for(User user : users) { List<Tweet>
tweets = user.getTweets(); for(Tweet tweet : tweets) { System.out.println(tweet.getBody()); } }
Observable.fromIterator(getUsers()) // .flatmap(user -> Observable .fromIterator(user.getTweets()) .map(Tweet::getBody) // .subscribe(System::out::println); //
20 List<User> users = getUsers(); for(User user : users) {
int tweetCount = 0; // List<Tweet> tweets = user.getTweets(); for(Tweet tweet : tweets) { if(tweetCount > 20) { // break; } System.out.println(tweet.getBody()); tweetCount++; // } }
20 Observable.fromIterator(getUsers()) // .flatmap(user -> Observable .fromIterator(user.getTweets()) .take(20)) // .map(Tweet::getBody)
// .subscribe(System::out::println); //
User Tweet
lter map atmap etc.. +
fromArray, fromIterator int[] array = { 1,2,3,4 } Observable.fromArray(array) .subscribe(System::out::println);
// => 1,2,3,4 ---1---2---3---4---------|--->
lter int[] array = { 1,2,3,4 } Observable.fromArray(array) .filter(data ->
data > 2) .subscribe(System::out::println); // => 3,4 -----------3---4---------|--->
map int[] array = { 1,2,3,4 } Observable.fromArray(array) .map(data ->
data * 2) .subscribe(System::out::println); // => 2,4,6,8 ----2---4--6---8---------|--->
skip int[] array = { 1,2,3,4 } Observable.fromArray(array) .skip(2) .subscribe(System::out::println);
// => 3,4 -----------3---4---------|--->
take int[] array = { 1,2,3,4 } Observable.fromArray(array) .take(2) .subscribe(System::out::println);
// => 1,2 -----------1---2---------|--->
delay int[] array = { 1,2,3,4 } Observable.fromArray(array) .delay(1, TimeUnit.SECOND)
.subscribe(System::out::println); // => 1,2,3,4 -----------1---2---3---4-|--->
Zip int[] array = { "A","B","C","D" } Observable a =
Observable.fromArray(array); Observable b = Observable.just(" "," "," "); Observable.zip(a,b, (left, right) -> left + right) .subscribe(System::out::println); // => A ,B ,C ---A---B---C---D---------|---> --- --- --- -----------|---> ZIP! ---A ---B ---C --------|--->
http://reactivex.io/documentation/operators.html
Rx minne Android Rx
Rx
Observable Observer Push Observer (Observable) (Observer) Observable Observer Observer @gomi_ningen
Observable.just("Hello") .subscribe(data -> println(data + globalHoge));
Observable <-> Observer
10^-6 concat, merge, zip
None
RP FRP
Rx Rx Rx
Rx Observer
RxJS Marbles Rx Hot Cold Hot Cold