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

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

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

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

F46c97bb74758d481531990654933050?s=128

RyotaMurohoshi

July 05, 2016
Tweet

Transcript

  1. 5.

    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. 8.

    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. 20.

    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. 31.
  5. 35.

    ࣹӨϝιου!ͱ!ΠϯσοΫε෇͖ࣹӨϝιουೋͭ࡞Γ͍ͨ // ࣹӨϝιου fun <TSource, TResult> Sequence<TSource> .select(selector: (TSource) ->

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