Skip to content

Instantly share code, notes, and snippets.

@GibsonRuitiari
Last active June 4, 2022 20:47
Show Gist options
  • Save GibsonRuitiari/6f75887af5a8f2868842062038c5d95d to your computer and use it in GitHub Desktop.
Save GibsonRuitiari/6f75887af5a8f2868842062038c5d95d to your computer and use it in GitHub Desktop.
mapNotNullTo Example
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