![]() ![]() Stay in touch: Contributing to Kotlin Releases Press Kit Security Blog Issue Tracker Brand assets Careers Kotlin is protected under the Kotlin Foundation and licensed under the Apache 2 license. index - the index of the value in the collection or sequence. You may need to decipher that every time you come back to it. the index of the value in the collection or sequence. The indices/ mapIndexed-solution rather hide what's going on. Java equivalent code only jumps over single. It's way easier to read when you come back. As you can see, Kotlin expects to exit the loop right after index childrenCount condition gets reached. Start learning Kotlin now Examples in Each Chapter Our 'Try it Yourself' editor makes it easy to learn Kotlin. Kotlin is used to develop Android apps, server side apps, and much more. Kotlin is easy to learn, especially if you already know Java (it is 100 compatible with Java). And I can only recommend you to use the flatMap instead. Kotlin is a modern, trending programming language. Depending on how complex your condition is, the indices themselvses will not suffice you. Note that if what you are trying to insert is static, solution with the indices is of course easier then the mapping I've presented above. It should be easy enough though to add that case. ![]() indexOf returns -1 or itemsToInsertAfterMatch = null). what is matched with what? and what is inserted when where?).Īll the above solutions did not yet deal with the case when an element wasn't found (e.g. If you do not must (and who forces you?), I wouldn't use such a construct. As you said you iterate over the list, maybe a flatMap is rather something for you (in this example I add "odd", "even" after elements that are odd/even): val list = listOf("1", "2", "3", "4")Ġ -> listOf(it, " listOf(it, " itemsToInsertAfterMatch?.let ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |