fun findBestIceCream(iceCreams: List<IceCream>): IceCream { val result = IceCream() for(iceCream in iceCreams) { // secret algorithm } return result } 229
fun findBestIceCream(iceCreams: List<IceCream>): IceCream { val result = IceCream() for(iceCream in iceCreams) { // secret algorithm } return result } 230
fun findBestIceCream(iceCreams: List<IceCream>): IceCream { val result = IceCream() for(iceCream in iceCreams) { // secret algorithm } return result } 231
fun findBestIceCream(iceCreams: List<IceCream>): IceCream { val result = IceCream() for(iceCream in iceCreams) { // secret algorithm } return result } 232
fun findBestIceCream(iceCreams: List<IceCream>): IceCream { val result = IceCream() var score = 0 for(iceCream in iceCreams) { // secret algorithm } return result } 233
fun findBestIceCream(iceCreams: List<IceCream>): Pair<IceCream, Int> { val result = IceCream() var score = 0 for(iceCream in iceCreams) { // secret algorithm } return result to score } 234
Kotlin Standard Library provides implementations for basic collection types: sets, lists, and maps. • Each type have two options: ◦ A read-only interface. ◦ Mutable interface with write operations. 236
the author as a Pair. class Book(val title: String, val author: String, val year: Int){ fun getTitleAndAuthor(): Pair<String,String>{ return Pair(title, author) } } 283
year as a Triple. class Book(val title: String, val author: String, val year: Int){ fun getTitleAndAuthor(): Pair<String,String>{ return Pair(title, author) } fun getTitleAndAuthorAndYear(): Triple<String,String, Int>{ return Triple(title, author, year) } } 284
sentence fun main() { val book = Book("Orlando", "Virginia Woolf", 1928) val (title, author, year) = book.getTitleAndAuthorAndYear() println("Here is your book $title written by $author in $year.") } 286
sentence fun main() { val book = Book("Orlando", "Virginia Woolf", 1928) val (title, author, year) = book.getTitleAndAuthorAndYear() println("Here is your book $title written by $author in $year.") } 287
functionality without having to inherit from the class or use a design patterns such as Decorator. Kotlin provides this ability using two methods. • Extension function • Extension property 331