Last active
June 4, 2022 20:47
-
-
Save GibsonRuitiari/6f75887af5a8f2868842062038c5d95d to your computer and use it in GitHub Desktop.
mapNotNullTo Example
This file contains 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
fun main() { | |
val stringListA = listOf(1,2,3,4,null) | |
val stringListContainer = mutableListOf<Int>() | |
// stringListA.mapNotNullTo(stringListContainer){ it?.times(2)} | |
// de-duplicate | |
val listAIterator = stringListA.iterator() | |
while (listAIterator.hasNext()){ | |
val element = listAIterator.next() | |
element?.times(2)?.let { | |
stringListContainer.add(it) | |
} | |
} | |
println(stringListContainer) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment