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

commonMain.extensions.Any.kt Maven / Gradle / Ivy

There is a newer version: 0.14.0
Show newest version
package io.fluidsonic.stdlib

import kotlin.contracts.*


public inline fun  Any.cast(): T {
	contract {
		returns() implies (this@cast is T)
	}

	return this as T
}


public inline fun  Any.castOrNull(): T? {
	contract {
		returnsNotNull() implies (this@castOrNull is T)
	}

	return this as? T
}


internal expect inline fun  T.freeze(): T


public inline fun  T?.ifNull(defaultValue: () -> T): T {
	contract {
		callsInPlace(defaultValue, InvocationKind.AT_MOST_ONCE)
	}

	return this ?: defaultValue()
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy