Skip to content

Instantly share code, notes, and snippets.

@DenWav
Created August 15, 2016 23:51
Show Gist options
  • Select an option

  • Save DenWav/8ce0a66926a480a8f6bf7574d56a4e26 to your computer and use it in GitHub Desktop.

Select an option

Save DenWav/8ce0a66926a480a8f6bf7574d56a4e26 to your computer and use it in GitHub Desktop.
inline fun <T> MutableIterable<T>.iter(func: MutableIterator<T>.(T) -> Unit) {
val iter = iterator()
while (iter.hasNext()) {
val item = iter.next()
func(iter, item)
}
}
fun example() {
val list = mutableListOf("one", "two", "three", "four")
list.iter {
println(it)
if (it == "three") {
remove()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment