Add mapNotNull extension
derektom14 opened this issue · comments
Derek Peirce commented
Add an extension method to each Rx chain that has a value to match Kotlin's mapNotNull
.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/map-not-null.html
Sample implementations:
fun <T, R> Single<T>.mapNotNull(transform: (T) -> R?) = flatMapMaybe { value ->
Maybe.fromCallable {
transform(value)
}
}
fun <T, R> Observable<T>.mapNotNull(transform: (T) -> R?) = flatMapIterable { value ->
listOfNotNull(transform(value))
}
Petrus Nguyễn Thái Học commented
I have created PR #251. Hope maintainer will look at it