Elye - A One Eye Dev By His Grace
1 min readMay 20, 2019

--

The below code is not good

fun process(stringList: List<String>?, removeString: String): Int? = stringList
?.filterNot { it == removeString }
?.map { it.length }
?.sum()

as it introduces a lots of unnecessary branches. Try create unit test for it, and see if you could easily achieve 100% branch coverage. You’ll understand what I meant. Optionally you could look at the decompile code, and see the longer code generated compare to using let to eliminate the extra ?.

--

--

Elye - A One Eye Dev By His Grace
Elye - A One Eye Dev By His Grace

Written by Elye - A One Eye Dev By His Grace

Sharing Software Learning, Life and Faith Journey

Responses (1)