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
690
3分でわかるSequence
KotlinのSequence処理の流れについて
@Kotlin Fest 2018
scache
August 25, 2018
Tweet
Share
More Decks by scache
See All by scache
ExoPlayerのトラック選択と再生中の解像度制限
sckm
0
62
Hyperion Item Nameplate
sckm
0
140
[紹介]Writing Your First Kotlin Compiler Plugin by Kevin Most
sckm
0
330
ChangeLogを読もう(1.2.70編)
sckm
1
350
Property + Getter
sckm
0
1.4k
略解reified
sckm
0
130
KDoc
sckm
1
800
Other Decks in Programming
See All in Programming
Immutable ActiveRecord
megane42
0
140
『品質』という言葉が嫌いな理由
korimu
0
160
チームリードになって変わったこと
isaka1022
0
190
Honoのおもしろいミドルウェアをみてみよう
yusukebe
1
200
Grafana Loki によるサーバログのコスト削減
mot_techtalk
1
120
Flutter × Firebase Genkit で加速する生成 AI アプリ開発
coborinai
0
150
SpringBoot3.4の構造化ログ #kanjava
irof
2
980
DevinとCursorから学ぶAIエージェントメモリーの設計とMoatの考え方
itarutomy
1
670
Spring gRPC について / About Spring gRPC
mackey0225
0
220
ASP. NET CoreにおけるWebAPIの最新情報
tomokusaba
0
360
データの整合性を保つ非同期処理アーキテクチャパターン / Async Architecture Patterns
mokuo
45
16k
なぜイベント駆動が必要なのか - CQRS/ESで解く複雑系システムの課題 -
j5ik2o
9
3.4k
Featured
See All Featured
Docker and Python
trallard
44
3.3k
The Cult of Friendly URLs
andyhume
78
6.2k
Automating Front-end Workflow
addyosmani
1367
200k
How STYLIGHT went responsive
nonsquared
98
5.4k
Designing for humans not robots
tammielis
250
25k
Rails Girls Zürich Keynote
gr2m
94
13k
Rebuilding a faster, lazier Slack
samanthasiow
80
8.8k
Optimising Largest Contentful Paint
csswizardry
34
3.1k
Building Your Own Lightsaber
phodgson
104
6.2k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Fashionably flexible responsive web design (full day workshop)
malarkey
406
66k
The Cost Of JavaScript in 2023
addyosmani
47
7.3k
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Λ͏͖͔ɺૢ࡞ཁૉ ʹΑͬͯมΘΔͷͰͦͷ࣌ʑʹஅ͠·͠ΐ͏