Created
August 16, 2016 00:26
-
-
Save DenWav/dd4a8a97471fe8ca7e3721063eb89b15 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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