Properly inline tryOrNull() (#1003)

Nullable params can't be inlined, default empty lambdas are therefore preferred.
This commit is contained in:
Marco Romano 2023-07-31 15:49:57 +02:00 committed by GitHub
parent 784b84d1e8
commit 2a59e6ae78
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -16,11 +16,11 @@
package io.element.android.libraries.core.data
inline fun <A> tryOrNull(noinline onError: ((Throwable) -> Unit)? = null, operation: () -> A): A? {
inline fun <A> tryOrNull(onError: ((Throwable) -> Unit) = { }, operation: () -> A): A? {
return try {
operation()
} catch (any: Throwable) {
onError?.invoke(any)
onError.invoke(any)
null
}
}