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

commonMain.com.github.mustafaozhan.scopemob.WhetherScope.kt Maven / Gradle / Ivy

The newest version!
/*
 Copyright (c) 2020 Mustafa Ozhan. All rights reserved.
 */
package com.github.mustafaozhan.scopemob

inline fun  T.whether(
    method: T.(condition: T) -> Boolean
): T? =
    if (this != null && method(this)) {
        this
    } else {
        null
    }

inline fun  T.whether(
    vararg method: T.(condition: T) -> Boolean
): T? =
    if (this != null) {
        if (method.all { it(this) }) {
            this
        } else {
            null
        }
    } else {
        null
    }

inline fun  T.whetherNot(
    method: T.(condition: T) -> Boolean
): T? =
    if (this != null && !method(this)) {
        this
    } else {
        null
    }

inline fun  T.whetherNot(
    vararg method: T.(condition: T) -> Boolean
): T? =
    if (this != null) {
        if (!method.all { it(this) }) {
            this
        } else {
            null
        }
    } else {
        null
    }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy