Having fun with Kotlin and Unicode

fun main(args: Array<String>) {
    val condition = args.isEmpty()

    val v0 = condition ʔ "true" ː "false"
    val v1 = condition ʔ "true" ː { "false" }
    val v2 = condition ʔ { "true" } ː "false"
    val v3 = condition ʔ { "true" } ː { "false" }

    val a = (1 ᐸᐸ 31) ᛁ 0x0f
}

class IfPart<T>(val cond: Boolean, val result: T?) {
    infix fun ː(elseBlock: () -> T): T = if (cond) result else elseBlock()
    infix fun ː(elseBlock: T): T = if (cond) result else elseBlock
}

infix fun <T> Boolean.ʔ(block: () -> T) = IfPart(this, if (!this) null else block())
infix fun <T> Boolean.ʔ(block: T) = IfPart(this, if (!this) null else block)

infix fun Int.ᐸᐸ(other: Int): Int = this shl other
infix fun Int.ᐳᐳ(other: Int): Int = this shr other

infix fun Int.ᛁ(other: Int): Int = this or other

:upside_down_face:

5 Likes

Don’t let the people from the ternary discussion see this :stuck_out_tongue_winking_eye:

2 Likes

It’s such a great moment to reinitiate that useless discussion!

BTW, some people are crazy enough to “extend” their language with Unicode. Especially when it does not have generics

2 Likes