Properly inline tryOrNull() (#1003)
Nullable params can't be inlined, default empty lambdas are therefore preferred.
This commit is contained in:
parent
e88e8069aa
commit
fb1299c955
1 changed files with 2 additions and 2 deletions
|
|
@ -16,11 +16,11 @@
|
||||||
|
|
||||||
package io.element.android.libraries.core.data
|
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 {
|
return try {
|
||||||
operation()
|
operation()
|
||||||
} catch (any: Throwable) {
|
} catch (any: Throwable) {
|
||||||
onError?.invoke(any)
|
onError.invoke(any)
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue