forked from upstream-mirrors/quik
Add support for nullable types with Flowable
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
package com.moez.QKSMS.common.util
|
||||
|
||||
data class Optional<out T>(val value: T?) {
|
||||
fun notNull() = value != null
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.moez.QKSMS.common.util.extensions
|
||||
|
||||
import com.moez.QKSMS.common.util.Optional
|
||||
import io.reactivex.Flowable
|
||||
|
||||
fun <T, R> Flowable<T>.mapNotNull(mapper: (T) -> R?): Flowable<R>
|
||||
= map { input -> Optional(mapper(input)) }
|
||||
.filter { optional -> optional.notNull() }
|
||||
.map { optional -> optional.value }
|
||||
Reference in New Issue
Block a user