Skip to content

Add mapNotNull extension #221

Open
@derektom14

Description

@derektom14

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))
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions