fetch Or Default
Executes the given block and returns its result, or default if an exception is thrown.
Unlike fetchOrNull { ... } ?: default, this preserves the distinction between a block that returns null vs a block that throws - only exceptions trigger the default.
CancellationException is always rethrown to preserve structured concurrency.
Example:
val hasProfilePicture: Boolean = fetchOrDefault(false) {
(user.getCanViewProfilePicture() ?: false) &&
(user.getUserRepresentationUrl()?.getHasProfilePicture() ?: false)
}Content copied to clipboard