狠狠撸
Submit Search
础苍诲谤辞颈诲て?贰颈迟丑别谤
2 likes
1,269 views
Fumihiko Shiroyama
@Shibuya.apk #3
Engineering
Read more
1 of 20
Download now
Download to read offline
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
More Related Content
More from Fumihiko Shiroyama
(7)
PDF
GCP HTTPロート?ハ?ランサ運用例
Fumihiko Shiroyama
?
PDF
GDG Tokyo Firebaseを使った Androidアプリ開発
Fumihiko Shiroyama
?
PDF
贵颈谤别产补蝉别て?惊くほと?简単に作れるリアルタイムイヘ?ントト?リフ?ンアフ?リ
Fumihiko Shiroyama
?
PDF
搁虫箩补惫补と辞辫迟颈辞苍补濒て?関数型补苍诲谤辞颈诲しよう
Fumihiko Shiroyama
?
PDF
Ops worksに今後期待するところ
Fumihiko Shiroyama
?
PDF
Wallet api
Fumihiko Shiroyama
?
PDF
Google io 2013_keynote
Fumihiko Shiroyama
?
GCP HTTPロート?ハ?ランサ運用例
Fumihiko Shiroyama
?
GDG Tokyo Firebaseを使った Androidアプリ開発
Fumihiko Shiroyama
?
贵颈谤别产补蝉别て?惊くほと?简単に作れるリアルタイムイヘ?ントト?リフ?ンアフ?リ
Fumihiko Shiroyama
?
搁虫箩补惫补と辞辫迟颈辞苍补濒て?関数型补苍诲谤辞颈诲しよう
Fumihiko Shiroyama
?
Ops worksに今後期待するところ
Fumihiko Shiroyama
?
Wallet api
Fumihiko Shiroyama
?
Google io 2013_keynote
Fumihiko Shiroyama
?
Recently uploaded
(6)
PDF
AWS BedrockによるIoT実装例紹介とAI進化の展望@AWS Summit ExecLeaders Scale Session
Osaka University
?
PDF
【础滨罢搁滨翱厂】人惫蝉生成础滨でジェスチャーゲームを础滨罢滨搁翱厂を使ってしてみた
ueda0116
?
PDF
フィシ?カル础滨时代のセキュリティ:ロホ?ティクスと础滨セキュリティの融合のあり方
Osaka University
?
PDF
React Native vs React Lynx (React Native Meetup #22)
Taiju Muto
?
PDF
音学シンポジウム2025 招待讲演 远隔会话音声认识のための音声强调フロントエント?:概要と我々の取り组み
Tsubasa Ochiai
?
PPTX
[Liberaware] Engineer Summer Internship.pptx
koyamakohei
?
AWS BedrockによるIoT実装例紹介とAI進化の展望@AWS Summit ExecLeaders Scale Session
Osaka University
?
【础滨罢搁滨翱厂】人惫蝉生成础滨でジェスチャーゲームを础滨罢滨搁翱厂を使ってしてみた
ueda0116
?
フィシ?カル础滨时代のセキュリティ:ロホ?ティクスと础滨セキュリティの融合のあり方
Osaka University
?
React Native vs React Lynx (React Native Meetup #22)
Taiju Muto
?
音学シンポジウム2025 招待讲演 远隔会话音声认识のための音声强调フロントエント?:概要と我々の取り组み
Tsubasa Ochiai
?
[Liberaware] Engineer Summer Internship.pptx
koyamakohei
?
Ad
础苍诲谤辞颈诲て?贰颈迟丑别谤
1.
AndroidでEither 2015-09-11 @Shibuya.apk #3
2.
自己紹介 ? 白山?文彦 ? 株式会社マナボ?技術者 ?
@fushiroyama
3.
贰颈迟丑别谤とは
4.
Either a b
= Left a ? Right b
5.
失敗または成功を表す データ型
6.
(error_code, "OK Status") タプルとちょっと 似てる?
7.
最大の違いはEitherをEither のままチェインして加工した り出来る 難しい言い方をすると 「モナド」
8.
Either<Left, Right>
9.
? Left ? (慣習的に)エラーケースの値 ?
Right ? (慣習的に)正常ケースの値 ? rightの正しいと右の意味が掛かってる
10.
こんな感じで使う
11.
Either<Throwable, String> either; if
(response.getCode() != 200) { either = new Either.Left<>(new RuntimeException("error code"); } else { either = new Either.Right<>("Right value!"); }
12.
何が嬉しいのか?
13.
おいしくない例 if (either.isRight) { either.handleRight(); }
else { either.handleLeft(); } 擬似コード ですよ
14.
おいっしい例 Either<Throwable, String> either; if
(response.getCode() != 200) { either = new Either.Left<>(new RuntimeException("error code"); } else { either = new Either.Right<>("Right value!"); } either.map(String::toUpperCase); 中がRightかLeftか意識し なくていいのがミソ!
15.
? map /
?atMap などおなじみのメソッドがある ? 実体が何であるか気にする必要がないので抽象度が 高く本質にフォーカスしたコードが書ける ? 例外を使わないので複雑な例外ハンドリングが不要 ? RxJava/RxAndroidと相性抜群
16.
WeatherApiCreator.create(CurrentWeatherService.class).getByCityName(editTextCity.getText().toString()) .map(currentWeatherResponse -> { Either<Throwable,
String> either; if (currentWeatherResponse.getCode() != 200) { either = new Either.Left<>(new RuntimeException("error code: " + currentWeatherResponse.getCode())); } else { either = new Either.Right<>("Humidity: " + currentWeatherResponse.getMain().getHumidity()); } return either; }) .map(either -> either.map(String::toUpperCase)) .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) .subscribe( either -> either.apply( left -> Toast.makeText(this, left.getMessage(), Toast.LENGTH_SHORT).show(), right -> Toast.makeText(this, right, Toast.LENGTH_SHORT).show() ), error -> Toast.makeText(this, error.getMessage(), Toast.LENGTH_SHORT).show() );
17.
? Eitherの実装 ? https://gist.github.com/srym/ 0959ab481e598f0e4f12 ?
使用例のgist ? https://gist.github.com/srym/ 8c9ac01b6aad8097d809
18.
? Optionalに関する補足資料 ? http://blog.shiroyama.us/blog/2015/08/09/ optional-in-android/ ?
Eitherに関する補足資料 ? http://blog.shiroyama.us/blog/2015/08/10/ either-in-android/
19.
ご清聴ありがとうございました。
20.
マナボは颁厂担当者を募集しています!
Download