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
81
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
良いコードレビューとは
danimal141
10
9.6k
未経験でSRE、はじめました! 組織を支える役割と軌跡
curekoshimizu
1
230
もう一人で悩まない! 個の知見をチームの知見にする3つの習慣と工夫 / Into team knowledge.
honyanya
3
340
複数のAWSアカウントから横断で 利用する Lambda Authorizer の作り方
tc3jp
0
130
AIプログラミング雑キャッチアップ
yuheinakasaka
21
5.5k
Accelerate your key learnings of scaling modern Android apps
aldefy
0
100
Rubyと自由とAIと
yotii23
6
2k
「個人開発マネタイズ大全」が教えてくれたこと
bani24884
1
320
Jakarta EE meets AI
ivargrimstad
0
930
Kotlinの開発でも AIをいい感じに使いたい / Making the Most of AI in Kotlin Development
kohii00
5
2.2k
dbt Pythonモデルで実現するSnowflake活用術
trsnium
0
290
The Clean ArchitectureがWebフロントエンドでしっくりこないのは何故か / Why The Clean Architecture does not fit with Web Frontend
twada
PRO
65
22k
Featured
See All Featured
Large-scale JavaScript Application Architecture
addyosmani
511
110k
Side Projects
sachag
452
42k
A better future with KSS
kneath
238
17k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
53k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
3.7k
Bootstrapping a Software Product
garrettdimon
PRO
307
110k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
2.1k
Building Flexible Design Systems
yeseniaperezcruz
328
38k
Raft: Consensus for Rubyists
vanstee
137
6.8k
Art, The Web, and Tiny UX
lynnandtonic
298
20k
A Modern Web Designer's Workflow
chriscoyier
693
190k
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Λ͏͖͔ɺૢ࡞ཁૉ ʹΑͬͯมΘΔͷͰͦͷ࣌ʑʹஅ͠·͠ΐ͏