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
640
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
300
ChangeLogを読もう(1.2.70編)
sckm
1
310
Property + Getter
sckm
0
1.3k
略解reified
sckm
0
130
KDoc
sckm
1
750
Other Decks in Programming
See All in Programming
ログラスを支える設計標準について / loglass-design-standards
urmot
10
2.1k
[スクリプト] Swiftの型推論を学ぼう
omochi
1
180
元気予報
suu_mire0726
0
850
コードレビューで学ぶ!Kotlinオブジェクト指向デザインパターン
akkie76
2
170
try! Swift Tokyo 2024 参加報告 / try! Swift Tokyo 2024 Report
hironytic
0
160
educure_カリキュラム生操作マニュアル.pdf
linew_official
0
380
OpenTelemetry のサービスという概念について
azukiazusa1
2
1k
受託開発でGitLab CI を活用していく
xiombatsg
1
260
Folding Cheat Sheet #3
philipschwarz
PRO
0
110
Swiftの型推論を学ぼう | Let's Learn About Type Inference in Swift
omochi
3
3.4k
チーム力を高めるスクラム実践法:カンバン公開と課題攻略について - ニフティのスクラムトーク Vol. 2 - NIFTY Tech Talk #18
niftycorp
PRO
1
110
Designing for tomorrow's programming workflows
honnibal
PRO
2
100
Featured
See All Featured
Faster Mobile Websites
deanohume
296
30k
Designing on Purpose - Digital PM Summit 2013
jponch
110
6.4k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
272
12k
From Idea to $5000 a Month in 5 Months
shpigford
377
45k
The Art of Programming - Codeland 2020
erikaheidi
41
12k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
657
120k
Product Roadmaps are Hard
iamctodd
43
9.7k
How to Ace a Technical Interview
jacobian
272
22k
The Invisible Side of Design
smashingmag
293
49k
Typedesign – Prime Four
hannesfritz
36
2k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
60
14k
Web development in the modern age
philhawksworth
201
10k
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Λ͏͖͔ɺૢ࡞ཁૉ ʹΑͬͯมΘΔͷͰͦͷ࣌ʑʹஅ͠·͠ΐ͏