Fragmented - Android Developer Podcast

109: Learning Kotlin - Sequences the new Iterables

Informações:

Sinopse

In this episode of Fragmented, we go back to learning some Kotlin and look at the Iterable like data structure introduced called "Sequences". What is a sequence? How is it different from Iterable? When should I use it? Show Notes Kotlin Sequence Java Iterable vs Iterator - stackoverflow.com Eager/Lazy Eager evaluation: val lst = listOf(1, 2) val lstMapped: List = lst.map { print("$it "); it * it } print("before sum ") val sum = lstMapped.sum() // prints "1 2 before sum" Lazy evaluation: val seq = sequenceOf(1, 2) val seqMapped: Sequence = seq.map { print("$it "); it * it } print("before sum ") val sum = seqMapped.sum() // prints "before sum 1 2" Source stackoverflow.com answer Intermediate and terminal operations Notice that at each chain operation, a new temporary list is created: data class Person(val name: String, val age: Int) fun main(args: Array) { val people = listOf(Person("Chris Martin", 31),