arrow-core-data / arrow.core / ListK / mapNotNull

mapNotNull

fun <B> mapNotNull(f: (A) -> B?): ListK<B>

Returns a ListK containing the transformed values from the original ListK filtering out any null value.

Example:

import arrow.core.*

//sampleStart
val evenStrings = listOf(1, 2).k().mapNotNull {
  when (it % 2 == 0) {
    true -> it.toString()
    else -> null
  }
}
//sampleEnd

fun main() {
  println("evenStrings = $evenStrings")
}

Do you like Arrow?

Arrow Org
<