All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.airbnb.epoxy.processor.Asyncable.kt Maven / Gradle / Ivy

There is a newer version: 5.1.4
Show newest version
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
                }
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy