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
630
怖くないReactive Extensions
社内の新卒向け座学の資料から社内情報を削ったりしたものです
いも
December 12, 2017
Tweet
Share
More Decks by いも
See All by いも
UnityプログラミングバイブルR6号宣伝&Unity Logging小話
adarapata
0
440
Unityテスト活動のふりかえり
adarapata
1
530
Gather.townはいいぞ その後
adarapata
1
1.5k
Unityでの開発事例
adarapata
3
22k
どこのご家庭にもあるシーンマネージャーの話
adarapata
1
7.7k
Gather.townはいいぞ
adarapata
2
2.3k
宴はいいぞ
adarapata
0
1.4k
わかった気になるモブプログラミング
adarapata
1
99
モブワークっぽいのをやっている話/Trying mobwork
adarapata
2
1.2k
Other Decks in Technology
See All in Technology
JAWS DAYS 2025 アーキテクチャ道場 事前説明会 / JAWS DAYS 2025 briefing document
naospon
0
2.5k
手を動かしてレベルアップしよう!
maruto
0
230
スキルだけでは満たせない、 “組織全体に”なじむオンボーディング/Onboarding that fits “throughout the organization” and cannot be satisfied by skills alone
bitkey
0
190
AWS Well-Architected Frameworkで学ぶAmazon ECSのセキュリティ対策
umekou
2
150
Pwned Labsのすゝめ
ken5scal
2
460
AI Agent時代なのでAWSのLLMs.txtが欲しい!
watany
3
250
データベースの負荷を紐解く/untangle-the-database-load
emiki
2
530
Snowflakeの開発・運用コストをApache Icebergで効率化しよう!~機能と活用例のご紹介~
sagara
1
490
Two Blades, One Journey: Engineering While Managing
ohbarye
4
2.2k
IAMのマニアックな話2025
nrinetcom
PRO
6
1.2k
Apache Iceberg Case Study in LY Corporation
lycorptech_jp
PRO
0
340
【内製開発Summit 2025】イオンスマートテクノロジーの内製化組織の作り方/In-house-development-summit-AST
aeonpeople
2
960
Featured
See All Featured
The Cost Of JavaScript in 2023
addyosmani
47
7.4k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.3k
Bootstrapping a Software Product
garrettdimon
PRO
306
110k
Visualization
eitanlees
146
15k
Java REST API Framework Comparison - PWX 2021
mraible
29
8.4k
Facilitating Awesome Meetings
lara
52
6.2k
Documentation Writing (for coders)
carmenintech
67
4.6k
Practical Orchestrator
shlominoach
186
10k
It's Worth the Effort
3n
184
28k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
366
25k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
40
2k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
12
1k
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