Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mapNotNull extension #221

Open
derektom14 opened this issue Oct 6, 2019 · 1 comment · May be fixed by #251
Open

Add mapNotNull extension #221

derektom14 opened this issue Oct 6, 2019 · 1 comment · May be fixed by #251

Comments

@derektom14
Copy link

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))
}
@hoc081098
Copy link

I have created PR #251. Hope maintainer will look at it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants