Skip to content

Instantly share code, notes, and snippets.

@pakoito
Created October 22, 2016 09:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pakoito/0fd5d1bd6c1523ad965b52cc7b592433 to your computer and use it in GitHub Desktop.
Save pakoito/0fd5d1bd6c1523ad965b52cc7b592433 to your computer and use it in GitHub Desktop.
Revisiting types in Kotlin - functions and collections
// 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