mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-22 13:48:52 +01:00
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