Youssef Shoaib [MOD]
06/07/2023, 5:41 PMRaise
completely on both the happy and error paths by utilising non-local returns. Might be an interesting thought exercise! It boils down to the pattern of:
val value = someValue.getOrElse { return Either.Left(it) }
someFunction(value).getOrElse { return Either.Left(it) }
by turning return Etiher.Left(it)
into a function that's available only locally within an "anonymous lambda inline function".
The gist of it is it would allow:
either { raise: (String) -> Nothing ->
someFunction(arg, raise)
}
or, if the extra possibility of functional context receivers being inlined is implemented:
either {
someFunction(arg)
}
but with no exception throwing magic!
It would also allow for things like break
within a forEach