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

me.qnox.builder.BuildContext.kt Maven / Gradle / Ivy

package me.qnox.builder

import kotlin.reflect.KClass

class BuildContext {
    private val preprocessors = mutableMapOf, (Any) -> Unit>()

    fun  preprocess(builder: T) {
        val preprocessor = findPreprocessor(builder::class) as ((T) -> Unit)?
        preprocessor?.let { it(builder) }
    }

    private fun  findPreprocessor(type: KClass): ((T) -> Unit)? = preprocessors[type]

    fun  preprocess(type: KClass, preprocessor: T.() -> Unit) {
        preprocessors[type] = preprocessor as (Any) -> Unit
    }
}

fun builderContext(block: BuildContext.() -> Unit): BuildContext = BuildContext().apply(block)




© 2015 - 2024 Weber Informatics LLC | Privacy Policy