what is the best way to process a list and produce...
# getting-started
n
what is the best way to process a list and produce a new list with potentially fewer elements? I know I could do
listOf(1,2,3).mapNotNull { if (it %2 != 0) "hi ${it}" else null }
but (a) that relies on
null
never being a valid result element and (b) does not work for
flatMap
. Perhaps I should just use a classical for loop and add to the result list?