Last active
June 17, 2017 00:10
-
-
Save aldajo92/d5d3e4cd2e47b01df6fc834fd2ffbcc8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* https://antonioleiva.com/collection-operations-kotlin/ | |
*/ | |
fun main(args: Array<String>) { | |
val list = listOf(1, 2, 3, 4, 5, 6) | |
println(list.any { it % 2 == 0 }) | |
println(list.map { it + 1 }) | |
val listPair = listOf(2, 4, 6, 8, 10) | |
println(listPair.all { it % 2 == 0}) | |
val listRepeat = listOf(2, 5, 2, 5, 8, 9) | |
println(listRepeat.count { it == 2}) | |
val listAccumulate = listOf(2, 2, 3, 4, 1) | |
println(listAccumulate.fold(0) { total, next -> total + next}) | |
println(listAccumulate.foldRight(0) {total, next -> total + next}) | |
println("----------------------") | |
val listWords = listOf("hello", "hola", "hallo") | |
listWords.forEach{ println(it) } | |
listWords.forEachIndexed{ index, value -> println("position $index contains a $value") } | |
val listMax = listOf(9, 9, 9, 111, 0, 0) | |
val maxValue = listMax.max() | |
println("max value is $maxValue") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment