commonMain.com.github.mustafaozhan.scopemob.inCaseScope.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of submob-metadata Show documentation
Show all versions of submob-metadata Show documentation
Set of useful scope and Higher-order functions
The newest version!
/*
Copyright (c) 2020 Mustafa Ozhan. All rights reserved.
*/
package com.github.mustafaozhan.scopemob
inline fun T.inCase(
condition: Boolean?,
method: T.(T) -> Unit
): T {
if (condition == true) {
method(this)
}
return this
}
inline fun T.inCaseNot(
condition: Boolean?,
method: T.(T) -> Unit
): T {
if (condition == false) {
method(this)
}
return this
}
inline fun T.inCase(
vararg condition: T.(T) -> Boolean?,
method: T.(T) -> Unit
): T {
if (condition.all { it(this) == true }) {
method(this)
}
return this
}
inline fun T.inCaseNot(
vararg condition: T.(T) -> Boolean?,
method: T.(T) -> Unit
): T {
if (condition.all { it(this) == false }) {
method(this)
}
return this
}