tech.figure.classification.asset.util.extensions.GenericExtensions.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ac-util Show documentation
Show all versions of ac-util Show documentation
Various tools for interacting with the Asset Classification smart contract
package tech.figure.classification.asset.util.extensions
/**
* All extensions in this library are suffixed with "Ac" to ensure they do not overlap with other libraries' extensions.
*/
/**
* The functional equivalent of an elvis operator, allowing default values to be derived when an elvis operator
* would cause weird-looking syntax, like parenthetical enclosures that unnecessarily obfuscate meaning.
*/
fun T?.elvisAc(default: () -> T): T = this ?: default()
/**
* Functionally identical to Kotlin Stdlib's .also extension function, except that the logic will only execute if the
* condition value is passed as 'true'.
*/
fun T.alsoIfAc(condition: Boolean, action: () -> Unit): T = this.also {
if (condition) {
action.invoke()
}
}
fun T.wrapListAc(): List = listOf(this)
fun T.wrapSetAc(): Set = setOf(this)
inline fun T.wrapArrayAc(): Array = arrayOf(this)