File tree Expand file tree Collapse file tree 2 files changed +25
-2
lines changed
main/java/io/getstream/android/core/api/utils
test/java/io/getstream/android/core/api/utils Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -47,5 +47,14 @@ public operator fun Throwable.plus(other: Throwable): StreamAggregateException {
4747 * [StreamAggregateException] if either [Result] is a failure.
4848 */
4949@StreamInternalApi
50- public operator fun <T , R > Result<T>.times (other : Result <R >): Result <Pair <T , R >> =
51- this .flatMap { first -> other.map { second -> first to second } }
50+ public operator fun <T , R > Result<T>.times (other : Result <R >): Result <Pair <T , R >> {
51+ when {
52+ this .isFailure && other.isFailure -> {
53+ return Result .failure(this .exceptionOrNull()!! + other.exceptionOrNull()!! )
54+ }
55+
56+ this .isFailure -> return Result .failure(this .exceptionOrNull()!! )
57+ other.isFailure -> return Result .failure(other.exceptionOrNull()!! )
58+ }
59+ return Result .success(this .getOrThrow() to other.getOrThrow())
60+ }
Original file line number Diff line number Diff line change @@ -103,4 +103,18 @@ class AlgebraTest {
103103 assertTrue(combined.isFailure)
104104 assertSame(failure, combined.exceptionOrNull())
105105 }
106+
107+ @Test
108+ fun `times propagates both results when both fail` () {
109+ val failure = IllegalArgumentException (" broken" )
110+ val failure2 = IllegalArgumentException (" broken2" )
111+ val left = Result .failure<String >(failure)
112+ val right = Result .failure<String >(failure2)
113+
114+ val combined = left * right
115+
116+ assertTrue(combined.isFailure)
117+ val exception = combined.exceptionOrNull() as StreamAggregateException
118+ assertEquals(listOf (failure, failure2), exception.causes)
119+ }
106120}
You can’t perform that action at this time.
0 commit comments