Skip to content

Instantly share code, notes, and snippets.

@travisdachi
Last active August 17, 2016 22:45
Show Gist options
  • Save travisdachi/0d35517f24ffa4c6080a8da47f537532 to your computer and use it in GitHub Desktop.
Save travisdachi/0d35517f24ffa4c6080a8da47f537532 to your computer and use it in GitHub Desktop.
for (p in list) println(p)
list.forEach { println(it) }
// Taken from Kotlin standard library
public inline fun <T> Iterable<T>.forEach(action: (T) -> Unit): Unit {
for (element in this) action(element)
}
for (i in 0..list.size - 1) println("list[$i]: ${list[i]}")
for (i in list.indices) println("list[$i]: ${list[i]}")
list.forEachIndexed { i, present -> println("list[$i]: $present") }
// Taken from Kotlin standard library
public inline fun <T> Iterable<T>.forEachIndexed(action: (Int, T) -> Unit): Unit {
var index = 0
for (item in this) action(index++, item)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment