Rafael Costa
04/16/2026, 12:23 AMif (someString == null) {
methodThatReturnsResultLikeType()
} else if (someString.isBlank()) {
methodThatAlsoReturnsResultLikeType()
} else {
yetAnotherMethodThatReturnsSameType()
}.onSuccess { println("SUCCESS!") }
.onFailure { println("FAILURE!") }
Apparently, the onSuccess and onFailure are only applied to the second if-else expression (the one that actually starts with else if ) and not to the whole if expression. Such that if someString is null, the onSuccess / onFailure is not called at all.
I have to either surround the whole if expression with parenthesis or add a new variable capturing the result.
(I'm sorry if this is not the right channel 🙏. Please do LMK)jw
04/16/2026, 12:28 AMjw
04/16/2026, 12:28 AMelse.jw
04/16/2026, 12:30 AM{ .. } on the else would otherwise be () -> Result<Whatever> and there's no onSuccess function on that typejw
04/16/2026, 12:30 AMfun <T> (() -> Result<T>).onSuccess(..) if it would probably take precedence and bind to the final else.jw
04/16/2026, 12:31 AMonSuccess is only available on Result<T> means that it binds to the inner `if`/`else`Rafael Costa
04/16/2026, 12:32 AMwhen (someString) {
null -> {
methodA()
}
else -> if (someString.isBlank()) {
methodB()
} else {
methodC()
}.onSuccess { onSuccess(it) }
.onFailure { onFailure(it) }
}Rafael Costa
04/16/2026, 12:32 AMjw
04/16/2026, 12:32 AMRafael Costa
04/16/2026, 12:33 AMjw
04/16/2026, 12:34 AM"hello" + "world".reverse() should return the whole "hello world" string as reversedRafael Costa
04/16/2026, 12:34 AMRafael Costa
04/16/2026, 12:34 AMjw
04/16/2026, 12:35 AM{ } to return a lambda, but the function call might take precedence when creating the expression treeRafael Costa
04/16/2026, 12:35 AMsure but that's like sayingis it really? I really don't see it that way, but I guess this is where syntax and how human beings perceive it can be a bit subjective 😅should return the whole "hello world" string as reversed"hello" + "world".reverse()
jw
04/16/2026, 12:36 AMelse if. There's just else, and so the second branch of the outer conditional itself contains an expression-producing conditionalYoussef Shoaib [MOD]
04/16/2026, 12:36 AMRafael Costa
04/16/2026, 12:36 AMephemient
04/16/2026, 12:38 AMRafael Costa
04/16/2026, 12:39 AMephemient
04/16/2026, 12:39 AMephemient
04/16/2026, 12:39 AMRafael Costa
04/16/2026, 12:40 AM