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

io.smooth.constraint.Utils.kt Maven / Gradle / Ivy

The newest version!
package io.smooth.constraint

import io.smooth.constraint.resolution.ConstraintResolution


suspend fun > Pair>.getDetails() =
    second.getDetails(first)

suspend fun > Pair>.resolve() =
    second.resolve(first)

data class ConstraintResolutionDetails(
    val constraint: Constraint<*>,
    val resolution: ConstraintResolution, *>,
    val details: Any
){

    suspend fun resolve(){
        resolution.resolve(constraint)
    }

}

suspend fun Pair, List, *>>>.resolutionDetails() =
    second.mapNotNull {
        val details = it.getDetails(first)
        if (details != null) ConstraintResolutionDetails(first, it, details)
        else null
    }

suspend fun ConstraintsNotMet.resolutionDetails() =
    getResolutions().map {
        it.resolutionDetails()
    }.flatten()

suspend fun ConstraintsNotMet.getResolutions(): List, List, *>>>> {
    val service = ConstraintsService.getInstance()

    return blockingConstraints.mapNotNull {
        it to (service.getConstraintResolutions(it::class)?.map {
            it.get() as ConstraintResolution, *>
        } ?: arrayListOf())
    }
}






© 2015 - 2025 Weber Informatics LLC | Privacy Policy