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
3分でわかるSequence
Search
scache
August 25, 2018
Programming
1
680
3分でわかるSequence
KotlinのSequence処理の流れについて
@Kotlin Fest 2018
scache
August 25, 2018
Tweet
Share
More Decks by scache
See All by scache
Hyperion Item Nameplate
sckm
0
130
[紹介]Writing Your First Kotlin Compiler Plugin by Kevin Most
sckm
0
320
ChangeLogを読もう(1.2.70編)
sckm
1
340
Property + Getter
sckm
0
1.3k
略解reified
sckm
0
130
KDoc
sckm
1
780
Other Decks in Programming
See All in Programming
.NET のための通信フレームワーク MagicOnion 入門 / Introduction to MagicOnion
mayuki
1
1.8k
Realtime API 入門
riofujimon
0
150
AI時代におけるSRE、 あるいはエンジニアの生存戦略
pyama86
6
1.2k
Enabling DevOps and Team Topologies Through Architecture: Architecting for Fast Flow
cer
PRO
0
350
Ethereum_.pdf
nekomatu
0
470
ローコードSaaSのUXを向上させるためのTypeScript
taro28
1
650
Flutterを言い訳にしない!アプリの使い心地改善テクニック5選🔥
kno3a87
1
210
AWS Lambdaから始まった Serverlessの「熱」とキャリアパス / It started with AWS Lambda Serverless “fever” and career path
seike460
PRO
1
260
Missing parts when designing and implementing Android UI
ericksli
0
170
React CompilerとFine Grained Reactivityと宣言的UIのこれから / The next chapter of declarative UI
ssssota
3
150
Hotwire or React? ~アフタートーク・本編に含めなかった話~ / Hotwire or React? after talk
harunatsujita
1
120
アジャイルを支えるテストアーキテクチャ設計/Test Architecting for Agile
goyoki
9
3.3k
Featured
See All Featured
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
720
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
The Cost Of JavaScript in 2023
addyosmani
45
6.8k
Scaling GitHub
holman
458
140k
Optimising Largest Contentful Paint
csswizardry
33
2.9k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
364
24k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
Building Adaptive Systems
keathley
38
2.3k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
250
21k
The Invisible Side of Design
smashingmag
298
50k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
Transcript
3ͰΘ͔ΔSequence Kotlin Fest 2018 scache @scal_ch CyberAgent, Inc.
Sequenceͱ ❖ ListͱࣅͨίϨΫγϣϯૢ࡞͕ՄೳͳΠϯλϑΣʔε ❖ asSequenceͰIterator(List) -> Sequence ʹม
ྫ (1..100) .map { it * 10 } .filter {
it < 825 } .take(2)
ྫ (1..100).asSequence() .map { it * 10 } .filter {
it < 825 } .take(2) .toList()
࠷ऴతʹಘΒΕΔϦετಉ͡ ʢ෭࡞༻ͳ͠ͷ࣌) (1..100) .map { it * 10 } .filter
{ it < 825 } .take(2) (1..100).asSequence() .map { it * 10 } .filter { it < 825 } .take(2) .toList() [10, 20]
ListͱSequence ҧ͍ʁ
ૢ࡞ͷධՁॱ͕ҧ͏ ❖ ListઌߦධՁ ❖ SequenceԆධՁ
List ❖ Collectionૢ࡞(map, filterͳͲ)ͷͨͼʹ৽͍͠ListΛ࡞
List (1..100) .map { it * 10 } .filter {
it < 825 } .take(2)
List (1..100) .map { it * 10 } .filter {
it < 825 } .take(2)
List (1..100) .map { it * 10 } .filter {
it < 825 } .take(2) [10, 20, … , 1000]
List (1..100) .map { it * 10 } .filter {
it < 825 } .take(2) [10, 20, … , 820]
List (1..100) .map { it * 10 } .filter {
it < 825 } .take(2) [10, 20]
Sequence ❖ தؒૢ࡞(map, filterͳͲ)ͱऴૢ࡞(toListͳͲ)͕͋Δ ❖ ऴૢ࡞Λߦ͏·Ͱॲཧ͕࣮ߦ͞Εͳ͍
(1..100).asSequence() .map { it * 10 } .filter { it
< 825 } .take(2) .toList() Sequence
(1..100).asSequence() .map { it * 10 } .filter { it
< 825 } .take(2) .toList() Sequence
(1..100).asSequence() .map { it * 10 } .filter { it
< 825 } .take(2) .toList() Sequence
(1..100).asSequence() .map { it * 10 } .filter { it
< 825 } .take(2) .toList() Sequence
(1..100).asSequence() .map { it * 10 } .filter { it
< 825 } .take(2) .toList() Sequence
(1..100).asSequence() .map { it * 10 } .filter { it
< 825 } .take(2) .toList() Sequence
Sequence 1 2 3 … 100 map { it *
10 } filter { it < 825 } take(2) toList()
Sequence 1 2 3 … 100 map { it *
10 } 10 filter { it < 825 } take(2) toList()
Sequence 1 2 3 … 100 map { it *
10 } 10 filter { it < 825 } ↓ take(2) toList()
Sequence 1 2 3 … 100 map { it *
10 } 10 filter { it < 825 } ↓ take(2) ↓ toList()
Sequence 1 2 3 … 100 map { it *
10 } 10 filter { it < 825 } ↓ take(2) ↓ toList() 10
Sequence 1 2 3 … 100 map { it *
10 } 10 20 filter { it < 825 } ↓ ↓ take(2) ↓ ↓ toList() 10 20
Sequence 1 2 3 … 100 map { it *
10 } 10 20 filter { it < 825 } ↓ ↓ take(2) ↓ ↓ toList() 10 20
(1..100).asSequence() .map { it * 10 } .filter { it
< 825 } .take(2) .toList() Sequence [10, 20]
Sequenceͷಛ ❖ ListͱࣅͨίϨΫγϣϯૢ࡞͕Մೳ ❖ தؒ݁ՌͷΦϒδΣΫτΛੜ͠ͳ͍ ❖ SequenceΛॲཧ͢ΔϥϜμΠϯϥΠϯల։͞Εͳ͍ (ListͰՄೳ)
Sequence·ͱΊ ❖ ListͱࣅͨίϨΫγϣϯૢ࡞͕Մೳ ❖ தؒ݁ՌͷΦϒδΣΫτΛੜ͠ͳ͍ ❖ SequenceΛॲཧ͢ΔϥϜμΠϯϥΠϯల։͞Εͳ͍ (ListͰՄೳ) ཁૉૢ࡞ গ
=> List ଟ => Sequence
Kotlin ͔Θ͍͍ Have a nice Kotlin!
ิ ❖ ཁૉ͕গͳ͍߹ɺϥϜμ͕ΠϯϥΠϯԽ͞ΕΔ Listͷํ͕ॲཧ͕ૣ͍ ❖ େ͖ͳϑΝΠϧͷಡΈࠐΈΛߦ͏߹SequenceΛ͏ ͱྑ͍ ❖ ֦ுؔ BufferedReader.lineSequence()
ิ ❖ ListΛ͏͖͔SequenceΛ͏͖͔ɺૢ࡞ཁૉ ʹΑͬͯมΘΔͷͰͦͷ࣌ʑʹஅ͠·͠ΐ͏