-
I have been looking at for a while and I am slightly confused about its implementation.I wonder if it is intentional that the implementation will throw an NPE when a Result contains null as success value, or, at least I think it does looking at the source. Regards, Frank |
Beta Was this translation helpful? Give feedback.
Answered by
nomisRev
Aug 22, 2022
Replies: 2 comments 2 replies
-
Hey Frank, Okay, I see what you mean, and this is definitely a bug. val r = Result.success<Int?>(null)
r.zip(r) { x, y -> (x?.plus(y ?: 0)) ?: -1 } // shouldBe -1 but is java.lang.NullPointerException The proper implementation would check for inline fun <A, B, C> Result<A>.zip(b: Result<B>, transform: (A, B) -> C): Result<C> =
if (isSuccess && b.isSuccess) Result.success(transform(getOrNull() as A, b.getOrNull() as B))
else Result.failure((exceptionOrNull()?.apply { addSuppressed(b.exceptionOrNull()) } ?: b.exceptionOrNull())!!) |
Beta Was this translation helpful? Give feedback.
2 replies
-
I opened a PR with a fix #2804 |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
nomisRev
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I opened a PR with a fix #2804