I’m trying to avoid some sideways programming around cases where I need to evaluate something, do a conditional on that evaluation, and use the result. Particularly in the case of regex.
val resultA = regexA.matchEntire(str)
if (resultA != null) {
// Use result A
} else {
val resultB = regexB.matchEntire(str)
if (resultB != null) {
// Use result B
} else {
...
}
}
In JS you can capture a value inside a conditional, but Kotlin you can’t, so I’m wondering what’s the idiomatic way to do this in Kotlin?