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

jvmMain.io.mths.kava.Ensure.kt Maven / Gradle / Ivy

The newest version!
package io.mths.kava

import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.contract

@OptIn(ExperimentalContracts::class)
fun ValidationScope<*>.ensure(
    condition: Boolean
) {
    contract {
        returns() implies condition
    }
    if (!condition) {
        fail()
    }
}

inline fun  ValidationScope<*>.ensure(
    value: Type,
    assertions: Type.() -> Boolean
) {
    ensure (value.assertions())
}

inline fun ValidationScope<*>.ensure(
    assertions: () -> Boolean
) {
    ensure(assertions())
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy