3分でわかるSequence
by
scache
Link
Embed
Share
Beginning
This slide
Copy link URL
Copy link URL
Copy iframe embed code
Copy iframe embed code
Copy javascript embed code
Copy javascript embed code
Share
Tweet
Share
Tweet
Slide 1
Slide 1 text
3ͰΘ͔ΔSequence Kotlin Fest 2018 scache @scal_ch CyberAgent, Inc.
Slide 2
Slide 2 text
Sequenceͱ ❖ ListͱࣅͨίϨΫγϣϯૢ࡞͕ՄೳͳΠϯλϑΣʔε ❖ asSequenceͰIterator(List) -> Sequence ʹม
Slide 3
Slide 3 text
ྫ (1..100) .map { it * 10 } .filter { it < 825 } .take(2)
Slide 4
Slide 4 text
ྫ (1..100).asSequence() .map { it * 10 } .filter { it < 825 } .take(2) .toList()
Slide 5
Slide 5 text
࠷ऴతʹಘΒΕΔϦετಉ͡ ʢ෭࡞༻ͳ͠ͷ࣌) (1..100) .map { it * 10 } .filter { it < 825 } .take(2) (1..100).asSequence() .map { it * 10 } .filter { it < 825 } .take(2) .toList() [10, 20]
Slide 6
Slide 6 text
ListͱSequence ҧ͍ʁ
Slide 7
Slide 7 text
ૢ࡞ͷධՁॱ͕ҧ͏ ❖ ListઌߦධՁ ❖ SequenceԆධՁ
Slide 8
Slide 8 text
List ❖ Collectionૢ࡞(map, filterͳͲ)ͷͨͼʹ৽͍͠ListΛ࡞
Slide 9
Slide 9 text
List (1..100) .map { it * 10 } .filter { it < 825 } .take(2)
Slide 10
Slide 10 text
List (1..100) .map { it * 10 } .filter { it < 825 } .take(2)
Slide 11
Slide 11 text
List (1..100) .map { it * 10 } .filter { it < 825 } .take(2) [10, 20, … , 1000]
Slide 12
Slide 12 text
List (1..100) .map { it * 10 } .filter { it < 825 } .take(2) [10, 20, … , 820]
Slide 13
Slide 13 text
List (1..100) .map { it * 10 } .filter { it < 825 } .take(2) [10, 20]
Slide 14
Slide 14 text
Sequence ❖ தؒૢ࡞(map, filterͳͲ)ͱऴૢ࡞(toListͳͲ)͕͋Δ ❖ ऴૢ࡞Λߦ͏·Ͱॲཧ͕࣮ߦ͞Εͳ͍
Slide 15
Slide 15 text
(1..100).asSequence() .map { it * 10 } .filter { it < 825 } .take(2) .toList() Sequence
Slide 16
Slide 16 text
(1..100).asSequence() .map { it * 10 } .filter { it < 825 } .take(2) .toList() Sequence
Slide 17
Slide 17 text
(1..100).asSequence() .map { it * 10 } .filter { it < 825 } .take(2) .toList() Sequence
Slide 18
Slide 18 text
(1..100).asSequence() .map { it * 10 } .filter { it < 825 } .take(2) .toList() Sequence
Slide 19
Slide 19 text
(1..100).asSequence() .map { it * 10 } .filter { it < 825 } .take(2) .toList() Sequence
Slide 20
Slide 20 text
(1..100).asSequence() .map { it * 10 } .filter { it < 825 } .take(2) .toList() Sequence
Slide 21
Slide 21 text
Sequence 1 2 3 … 100 map { it * 10 } filter { it < 825 } take(2) toList()
Slide 22
Slide 22 text
Sequence 1 2 3 … 100 map { it * 10 } 10 filter { it < 825 } take(2) toList()
Slide 23
Slide 23 text
Sequence 1 2 3 … 100 map { it * 10 } 10 filter { it < 825 } ↓ take(2) toList()
Slide 24
Slide 24 text
Sequence 1 2 3 … 100 map { it * 10 } 10 filter { it < 825 } ↓ take(2) ↓ toList()
Slide 25
Slide 25 text
Sequence 1 2 3 … 100 map { it * 10 } 10 filter { it < 825 } ↓ take(2) ↓ toList() 10
Slide 26
Slide 26 text
Sequence 1 2 3 … 100 map { it * 10 } 10 20 filter { it < 825 } ↓ ↓ take(2) ↓ ↓ toList() 10 20
Slide 27
Slide 27 text
Sequence 1 2 3 … 100 map { it * 10 } 10 20 filter { it < 825 } ↓ ↓ take(2) ↓ ↓ toList() 10 20
Slide 28
Slide 28 text
(1..100).asSequence() .map { it * 10 } .filter { it < 825 } .take(2) .toList() Sequence [10, 20]
Slide 29
Slide 29 text
Sequenceͷಛ ❖ ListͱࣅͨίϨΫγϣϯૢ࡞͕Մೳ ❖ தؒ݁ՌͷΦϒδΣΫτΛੜ͠ͳ͍ ❖ SequenceΛॲཧ͢ΔϥϜμΠϯϥΠϯల։͞Εͳ͍ (ListͰՄೳ)
Slide 30
Slide 30 text
Sequence·ͱΊ ❖ ListͱࣅͨίϨΫγϣϯૢ࡞͕Մೳ ❖ தؒ݁ՌͷΦϒδΣΫτΛੜ͠ͳ͍ ❖ SequenceΛॲཧ͢ΔϥϜμΠϯϥΠϯల։͞Εͳ͍ (ListͰՄೳ) ཁૉૢ࡞ গ => List ଟ => Sequence
Slide 31
Slide 31 text
Kotlin ͔Θ͍͍ Have a nice Kotlin!
Slide 32
Slide 32 text
ิ ❖ ཁૉ͕গͳ͍߹ɺϥϜμ͕ΠϯϥΠϯԽ͞ΕΔ Listͷํ͕ॲཧ͕ૣ͍ ❖ େ͖ͳϑΝΠϧͷಡΈࠐΈΛߦ͏߹SequenceΛ͏ ͱྑ͍ ❖ ֦ுؔ BufferedReader.lineSequence()
Slide 33
Slide 33 text
ิ ❖ ListΛ͏͖͔SequenceΛ͏͖͔ɺૢ࡞ཁૉ ʹΑͬͯมΘΔͷͰͦͷ࣌ʑʹஅ͠·͠ΐ͏