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

CU-f51n03 Deprecate map2 in favor of zip in Resource.kt #2291

Merged
merged 3 commits into from Mar 3, 2021
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -151,13 +151,22 @@ sealed class Resource<out A> {
fun <B> flatMap(f: (A) -> Resource<B>): Resource<B> =
Bind(this, f)

@Deprecated(
"map2 will be renamed to zip to be consistent with Kotlin Std's naming, please use zip instead of map2",
ReplaceWith("zip(other, combine)")
)
fun <B, C> map2(other: Resource<B>, combine: (A, B) -> C): Resource<C> =
flatMap { r ->
other.map { r2 -> combine(r, r2) }
}

fun <B, C> zip(other: Resource<B>, combine: (A, B) -> C): Resource<C> =
flatMap { r ->
other.map { r2 -> combine(r, r2) }
}

fun <B> zip(other: Resource<B>): Resource<Pair<A, B>> =
map2(other, ::Pair)
zip(other, ::Pair)

class Bind<A, B>(val source: Resource<A>, val f: (A) -> Resource<B>) : Resource<B>()

Expand Down