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
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
790
Other Decks in Programming
See All in Programming
AppRouterを用いた大規模サービス開発におけるディレクトリ構成の変遷と問題点
eiganken
1
250
PHPカンファレンス 2024|共創を加速するための若手の技術挑戦
weddingpark
0
100
Compose UIテストを使った統合テスト
hiroaki404
0
110
Online-Dokumentation, die hilft: Strukturen, Prozesse, Tools
ahus1
0
110
Оптимизируем производительность блока Казначейство
lamodatech
0
800
今年のアップデートで振り返るCDKセキュリティのシフトレフト/2024-cdk-security-shift-left
tomoki10
0
300
Scalaから始めるOpenFeature入門 / Scalaわいわい勉強会 #4
arthur1
1
370
Androidアプリのモジュール分割における:x:commonを考える
okuzawats
1
250
Spatial Rendering for Apple Vision Pro
warrenm
0
290
Recoilを剥がしている話
kirik
5
7.8k
PHPとAPI Platformで作る本格的なWeb APIアプリケーション(入門編) / phpcon 2024 Intro to API Platform
ttskch
0
350
CQRS+ES の力を使って効果を感じる / Feel the effects of using the power of CQRS+ES
seike460
PRO
0
220
Featured
See All Featured
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
7
540
Why Our Code Smells
bkeepers
PRO
335
57k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
RailsConf 2023
tenderlove
29
960
For a Future-Friendly Web
brad_frost
176
9.5k
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
29
930
The Language of Interfaces
destraynor
155
24k
Into the Great Unknown - MozCon
thekraken
34
1.6k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
jQuery: Nuts, Bolts and Bling
dougneiner
62
7.6k
Optimising Largest Contentful Paint
csswizardry
33
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Λ͏͖͔ɺૢ࡞ཁૉ ʹΑͬͯมΘΔͷͰͦͷ࣌ʑʹஅ͠·͠ΐ͏