Skip to content

Instantly share code, notes, and snippets.

View broadwaylamb's full-sized avatar
🚵‍♂️

Sergej Jaskiewicz broadwaylamb

🚵‍♂️
View GitHub Profile
@broadwaylamb
broadwaylamb / Either.kt
Last active February 2, 2024 18:13
Zero-cost Either type in Kotlin
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.contract
import kotlin.contracts.InvocationKind
/**
* Zero-cost union type.
*
* [Left] and [Right] must not be subtypes of one another, and must not be the same type.
*/
@JvmInline