Updated on 2026-08-14
This commit is contained in:
parent
29915a8224
commit
e77c292230
4 changed files with 87 additions and 68 deletions
|
|
@ -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")
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue