is there a function similar to `map` that skips ov...
# announcements
j
is there a function similar to
map
that skips over an item if it doesn't satisfy a conditional statement? For example:
Copy code
data class Foo(val nullableName: String?)
data class Bar(val nonNullName: String)

val list: List<Foo> = fetchList()
list.map { item ->
  if (item.nullableName != null) {
      Bar(item.nullableName)
  }
}
k
You could filter first and then map
a
or
Copy code
list.mapNonNull {
  if (it.nullableName == null) null
  else Bar(item.nullableName)
}
j
thanks!
z
It's `mapNotNull`not
mapNonNull
. You get also IntelliJ hint 🙂