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
410
Unityテスト活動のふりかえり
adarapata
1
520
Gather.townはいいぞ その後
adarapata
1
1.5k
Unityでの開発事例
adarapata
3
22k
どこのご家庭にもあるシーンマネージャーの話
adarapata
1
7.5k
Gather.townはいいぞ
adarapata
2
2.3k
宴はいいぞ
adarapata
0
1.3k
わかった気になるモブプログラミング
adarapata
1
94
モブワークっぽいのをやっている話/Trying mobwork
adarapata
2
1.2k
Other Decks in Technology
See All in Technology
プロダクト組織で取り組むアドベントカレンダー/Advent Calendar in Product Teams
mixplace
0
660
シフトライトなテスト活動を適切に行うことで、無理な開発をせず、過剰にテストせず、顧客をビックリさせないプロダクトを作り上げているお話 #RSGT2025 / Shift Right
nihonbuson
3
1.5k
3年でバックエンドエンジニアが5倍に増えても破綻しなかったアーキテクチャ そして、これから / Software architecture that scales even with a 5x increase in backend engineers in 3 years
euglena1215
11
4.3k
終了の危機にあった15年続くWebサービスを全力で存続させる - phpcon2024
yositosi
28
25k
Alignment and Autonomy in Cybozu - 300人の開発組織でアラインメントと自律性を両立させるアジャイルな組織運営 / RSGT2025
ama_ch
1
1.7k
NOT VALIDな検査制約 / check constraint that is not valid
yahonda
1
110
いまからでも遅くないコンテナ座学
nomu
0
200
PHPerのための計算量入門/Complexity101 for PHPer
hanhan1978
6
1.5k
Evolving Architecture
rainerhahnekamp
3
220
DevFest 2024 Incheon / Songdo - Compose UI 조합 심화
wisemuji
0
250
UI State設計とテスト方針
rmakiyama
4
940
サーバーなしでWordPress運用、できますよ。
sogaoh
PRO
0
170
Featured
See All Featured
Speed Design
sergeychernyshev
25
720
GitHub's CSS Performance
jonrohan
1030
460k
Building a Scalable Design System with Sketch
lauravandoore
460
33k
What's in a price? How to price your products and services
michaelherold
244
12k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.2k
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.1k
Gamification - CAS2011
davidbonilla
80
5.1k
KATA
mclloyd
29
14k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
29
940
Building an army of robots
kneath
302
44k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
2k
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