Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
いつか役にたつかもしれないコレクション周りの5つのこと
Search
RyotaMurohoshi
July 05, 2016
Programming
810
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
いつか役にたつかもしれないコレクション周りの5つのこと
2016//07/05(火)に開催された「Kotlin 勉強会 #1 - 初めての Kotlin」で発表した資料です
http://connpass.com/event/33584/
RyotaMurohoshi
July 05, 2016
More Decks by RyotaMurohoshi
See All by RyotaMurohoshi
Tilemapのアップデートについて
ryotamurohoshi
0
100
Unityの合同同人誌や合同商業誌を書いてる僕は感想やレビューや評価が欲しい
ryotamurohoshi
0
630
Unity 2021.1での Unityパッケージの名称変更について
ryotamurohoshi
0
920
Odin Validationはいいぞ!
ryotamurohoshi
2
1.1k
Tilemapはいいぞ!2020 〜すごいぞ、プロジェクト専用拡張Brush〜
ryotamurohoshi
0
2.6k
Unityでも、新しいC#
ryotamurohoshi
0
1.5k
Riderはいいぞ!
ryotamurohoshi
1
3.8k
Riderのススメ〜俺はRiderここが好き〜
ryotamurohoshi
1
2.8k
Unity開発者に伝えたい.NETのこと
ryotamurohoshi
4
38k
Other Decks in Programming
See All in Programming
Vue Fes Japan の “作る側”に関わってみて
naokihaba
0
160
Lambda durable functionsでHuman in the Loopを楽に…楽に……
har1101
0
110
AIで開発が速くなった先で、開発チームは何を目指すか
shihochan
1
1.6k
phperだってパンチカードでコーディングしたい
o0h
PRO
0
350
Event is what happens
moro
2
890
sbt 2.0: takeoff
eed3si9n
0
160
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
1
750
Domain-Driven Transformation
hschwentner
2
2.3k
golang-bob.pdf
iwatsukayura
0
130
残高管理から台帳サービスへの進化
artoy
1
210
Long Living Tokens, Die, Die, Die! (or: The One Ring is Banned in Modern)
sylph01
0
330
The Rails Doctrine Decade
koic
2
600
Featured
See All Featured
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.4k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
4
1.2k
WENDY [Excerpt]
tessaabrams
14
40k
Darren the Foodie - Storyboard
khoart
PRO
4
4k
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
730
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
1
750
Done Done
chrislema
187
17k
A better future with KSS
kneath
240
18k
The Language of Interfaces
destraynor
162
27k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
Music & Morning Musume
bryan
48
7.4k
Transcript
ผʹܶతʹมΘΒͳ͍͚ΕͲ ͍͔ͭʹ͔ͨͭ͠Εͳ͍ ίϨΫγϣϯपΓͷ5ͭͷ͜ͱ @RyotaMurohoshi 2016/07/05(Ր)*͡ΊͯͷKotlin
ͦͷ1 ঢ়گʹԠͯ͡SequenceΛ͏͖ͳ݅
100000ߦͷJSON'LinesϑΝΠϧ ͜ΕΛ1ߦͣͭdataΫϥεͷΦϒδΣΫτʹม͠ ͋Δ݅Λຬͨ͢ΦϒδΣΫτΛ ࠷ॳ͔Β10͚݅ͩ֬ೝද͍ࣔͨ͠
List<T>ͷ߹
val lineList: List<String> = File("data.jsonlines").readLines() val result = lineList .map
{ convertToData(it) } .filter { filterData(it) } .take(10) for (it in result) { println(it) }
࠷ޙ·ͰϑΝΠϧΛಡΜͰ͠·͏
Sequence<T>ͷ߹
val result: List<PersonData> = File("data.jsonlines") .useLines { lineSequences: Sequence<String> ->
lineSequences .map { convertToData(it) } .filter { filterData(it) } .take(10) .toList() } for (it in result) { println(it) }
ϑΝΠϧΛ࠷ޙ·Ͱಡ·ͳ͍
ৄ͘͜͠ͷࢿྉͰʂ h"ps:/ /speakerdeck.com/ryotamurohoshi/sequencefalsehua8kotlin8dot8sequences8dot8sequence
ͦͷ2 ཁૉ͕ۭͷ࣌ͷaverageϝιου͕ 0.0Λฦͯ͠͠·͏݅
averageϝιουͱʁ List<Int>ͱ͔ͷฏۉܭࢉϝιου
͡Ό͋ɺཁૉ͕ۭͷ࣌ʁ
·͔͞ͷ0.0!
ͳͥͩʂʁ
͜Ε͡Όܭࢉ݁Ռ͕0.0ͩͬͨͷ͔ɺ ཁૉ͕ۭ͔ͩΒ0.0ͬͨͷ͔ ۠ผԽ͔ͭͳ͍ʂʂʂ
ͦͦͳͥDouble?ܕʹ͠ͳ͔ͬͨͷ͔ʁ maxminInt?Λฦ͢ͷʹʂ ͘͠ྫ֎Λ͛ͯཉ͍͠
ͦͷ3 Ωʔ͕ॏෳͨ͠ࡍͷassociateܥϝιου͕ɺ ྫ֎Λ͛ͳ͍݅
associateܥͷϝιουͱʁ Listͱ͔͔ΒMapΛͭ͘Δϝιου
data class Person( val id: Long,ɹval name: String, val teamId:
Long) // ॏෳidͷPersonଘࡏ͠ͳ͍ // ಉ͡teamIdΛ࣋ͭPersonଘࡏ͠͏Δ val personList : List<Person>ɹ= loadPersonList() // id͕ॏෳ͠ͳ͍ͷͰແ͠ val personMap : Map<Long, Person> = personList.associateBy { it.id } // ʲʂʂʂʳಉ͡teamIdΛͭཁૉ͕personListʹଘࡏ͠͏Δʂʂʂʂʂ val teamMap : Map<Long, Person> = personList.associateBy { it.teamId }
͠Key͕ॏෳͨ͠Βʁ
ޙউʂ ͋ͱ͕ͪ:ޙΖͷཁૉͰ্ॻ͖
ݸਓతʹྫ֎Λ͛ͯཉ͍͠
ͦͦMapΛͭ͘ͷͰ͋ΕɺKeyҰҙͳͷͳͣ Key͕ॏෳ͢ΔͷΛఆ͢ΔͳΒɺgroupByΛ͏͖
ಥવͷએ
C#ͷLINQޓͷϥΠϒϥϦ KotLinq࡞͍ͬͯ·͢ʂʂʂ h"ps:/ /github.com/RyotaMurohoshi/KotLinq
ࠓճͷTips KotLinqΛ࡞͍ͬͯΔࡍͷݟͰ͢
ͦͷ4 σϑΥϧτΠϯϙʔτ֦ுؔΛ ্ॻ͖Ͱ͖Δ݅
ࣗ࡞ϥΠϒϥϦKotLinqͷʹ takeͬͯϝιου͕͋Γ·͢ʂ
KotLinqͷtakeϝιου fun <TSource> Iterable<TSource>.take(count: Int): Sequence<TSource> = asSequence().take(count)
Μʁ
ඪ४ؔʹtakeͬͯ͋ͬͨΑ͏ͳ? fun <T> Iterable<T>.take(n: Int): List<T>
ඪ४ͰΠϯϙʔτͰ͖Δ֦ுؔ Λ্ॻ͖Ͱ͖Δ݅ʂ
ͦͷ5 ϝιουͷΦʔόʔϩʔυͱit͕ ૬ੑѱ͍݅ (͜Ε͋Μ·ΓίϨΫγϣϯؔͳ͍)
ࣹӨϝιου!ͱ!ΠϯσοΫε͖ࣹӨϝιουೋͭ࡞Γ͍ͨ // ࣹӨϝιου fun <TSource, TResult> Sequence<TSource> .select(selector: (TSource) ->
TResult): Sequence<TResult> // ΠϯσοΫε͖ࣹӨϝιου fun <TSource, TResult> Sequence<TSource> .select(selector: (TSource, Int) -> TResult): Sequence<TResult>
ࣹӨϝιου!ͱ!ΠϯσοΫε͖ࣹӨϝιου ҰҙʹܾΊΒΕͳ͍͔ΒίϯύΠϧΤϥʔ sequenceOf(1, 2, 3).select { it * 2 }
KotLinq(ͰɺΠϯσοΫε͖ࣹӨϝιουΛ ผ໊ʹ͠·ͨ͠ sequence.select { it * it }!ͱ͔͍ͨ͠͠
·ͱΊ • ঢ়گʹԠͯ͡SequenceΛ͏͖ͳ݅ • ཁૉ͕ۭͷ࣌ͷaverageϝιου͕0.0Λฦͯ͠͠·͏݅ • Ωʔ͕ॏෳͨ͠ࡍͷassociateܥϝιου͕ྫ֎Λ͛ͳ͍݅ • σϑΥϧτΠϯϙʔτ֦ுؔΛ্ॻ͖Ͱ͖Δ݅ •
ϝιουͷΦʔόʔϩʔυͱit͕૬ੑѱ͍݅
·ͱΊ KotLinqʹΛ