//Extensions for Jetpack Lifecycle/it.czerwinski.android.lifecycle.livedata/mapNotNull

mapNotNull

[androidJvm]
Content
fun <T, R> LiveData<T>.mapNotNull(transform: (T) -> R?): LiveData<R>
More info

Returns a LiveData emitting only the non-null results of applying the given transform function to each value emitted by this LiveData.

transform will be executed on the main thread.

Example:

val userOptionLiveData: LiveData<Option> = ... val userLiveData: LiveData = userOptionLiveData.mapNotNull { user -> user.getOrNull() }