Upgrade to Pro — share decks privately, control downloads, hide ads and more …

いつか役にたつかもしれないコレクション周りの5つのこと

 いつか役にたつかもしれないコレクション周りの5つのこと

2016//07/05(火)に開催された「Kotlin 勉強会 #1 - 初めての Kotlin」で発表した資料です

http://connpass.com/event/33584/

RyotaMurohoshi

July 05, 2016
Tweet

More Decks by RyotaMurohoshi

Other Decks in Programming

Transcript

  1. 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) }
  2. 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) }
  3. 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 }
  4. ࣹӨϝιου!ͱ!ΠϯσοΫε෇͖ࣹӨϝιουೋͭ࡞Γ͍ͨ // ࣹӨϝιου fun <TSource, TResult> Sequence<TSource> .select(selector: (TSource) ->

    TResult): Sequence<TResult> // ΠϯσοΫε෇͖ࣹӨϝιου fun <TSource, TResult> Sequence<TSource> .select(selector: (TSource, Int) -> TResult): Sequence<TResult>