com.airbnb.epoxy.processor.Asyncable.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of epoxy-processor Show documentation
Show all versions of epoxy-processor Show documentation
Epoxy is a system for composing complex screens with a ReyclerView in Android.
package com.airbnb.epoxy.processor
interface Asyncable {
val logger: Logger
fun Iterable.mapNotNull(
tag: String,
parallel: Boolean = true,
transform: (T) -> R?
): List {
return logger.measure(tag, numItems = count()) {
[email protected] {
try {
transform(it)
} catch (e: Exception) {
logger.logError(e, "$tag failed")
null
}
}
}
}
fun Iterable.forEach(
tag: String,
parallel: Boolean = true,
block: (T) -> Unit
) {
logger.measure(tag, numItems = count()) {
forEach {
try {
block(it)
} catch (e: Exception) {
logger.logError(e, "$tag failed")
}
}
}
}
fun Iterable.filter(
tag: String,
parallel: Boolean = true,
block: (T) -> Boolean
): List {
return logger.measure(tag, numItems = count()) {
filter {
try {
block(it)
} catch (e: Exception) {
logger.logError(e, "$tag failed")
false
}
}
}
}
fun Map.forEach(
tag: String,
parallel: Boolean = true,
block: (K, V) -> Any?
) {
logger.measure(tag, numItems = size) {
forEach {
try {
block(it.key, it.value)
} catch (e: Exception) {
logger.logError(e, "$tag failed")
}
}
}
}
fun Map.mapNotNull(
tag: String,
parallel: Boolean = true,
transform: (K, V) -> R?
): List {
return logger.measure(tag, numItems = count()) {
[email protected] {
try {
transform(it.key, it.value)
} catch (e: Exception) {
logger.logError(e, "$tag failed")
null
}
}
}
}
}