Created
October 22, 2016 09:59
-
-
Save pakoito/0fd5d1bd6c1523ad965b52cc7b592433 to your computer and use it in GitHub Desktop.
Revisiting types in Kotlin - functions and collections
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
// fun <T, R> Iterable<T>.map(transform: (T) -> R): List<R> | |
// fun <T> Iterable<T>.filter(predicate: (T) -> Boolean): List<T> | |
fun main(args: Array<String>) { | |
val immutable = listOf(1, 2, 3, 4, 5) | |
// immutable.add(6) | |
val mutable = mutableListOf(1, 2, 3, 4, 5) | |
mutable.add(6) | |
val otherElements = mutable.map({ value -> | |
value + 1 | |
}).filter { | |
it % 2 == 0 | |
} | |
// otherElements.add(6) | |
println(otherElements); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment