Skip to content

Instantly share code, notes, and snippets.

@DenWav
Created August 16, 2016 00:26
Show Gist options
  • Select an option

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

Select an option

Save DenWav/dd4a8a97471fe8ca7e3721063eb89b15 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()
iter.func(item)
}
}
fun example() {
val list = mutableListOf("one", "two", "three", "four")
list.iter { anotherNameOfMyChoosingBesidesIt ->
println(anotherNameOfMyChoosingBesidesIt)
if (anotherNameOfMyChoosingBesidesIt == "three") {
remove()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment