Updated on 2026-08-14

This commit is contained in:
Tangem 2024-10-15 18:50:21 +03:00
parent 29915a8224
commit e77c292230
4 changed files with 87 additions and 68 deletions

View file

@ -11,4 +11,19 @@ interface Converter<I : Any, O : Any?> {
fun convertSet(input: Collection<I>): Set<O> {
return input.mapTo(hashSetOf(), ::convert)
}
fun convertListIgnoreErrors(input: Collection<I>, onError: ((Throwable) -> Unit)? = null): List<O> {
return input.mapNotNull {
try {
convert(it)
} catch (throwable: Throwable) {
onError?.invoke(throwable)
null
}
}
}
fun <T> T?.asMandatory(name: String): T {
return this ?: error("$name must not be null")
}
}