I know about infix operators, as well as typealias...
# announcements
j
I know about infix operators, as well as typealias in Kotlin, but my understanding is that I wouldn’t be able to do something equivalent in Kotlin. We can’t overload or change the keywords at all. Right?
👌 2
Thanks @hho. I guess that makes it safer, but I was hoping for an April Fool’s Pull Request I could put in at my office 😅
s
Fortunately, no you cannot do that 😮
h
Though you can have a lot of "fun" (pun not intended) with operators: https://github.com/angryziber/kotlin-puzzlers/tree/master/src/operators
🙌 1
i
only if you use the backtick (`) around the identifier's name
🤔 2
b
this yeet IllegalStateException()
is closest thing to your example I can imagine
✔️ 1
j
literally what I ended up doing
I improved it further
😂 1
Screenshot 2019-04-01 at 13.48.33.png
k
But why?
j
doing stupid things to see if I can fuels my existence
also it usually ends up with me learning something new.
👆 2
r
Copy code
inline operator fun Throwable.not(): Nothing = throw this

fun main() {
    val error = Throwable()
    !error
}
(In the ‘weird things you can do’ category)
👍 1
😂 1
🤔 1
j
clever
r
Copy code
inline operator fun Throwable.invoke(): Nothing = throw this

fun main() {
    IllegalStateException()()
}
j
😬
r
Copy code
object yeet {
   inline infix fun new(e: Exception) = throw e
}

if (tRsp.error) {
    yeet new Exception()
}
If you want to stick to the original example
🤣 1
👌 5
j
I have to say, putting “new” as an infix function in kotlin is the perfect abomination
r
😁
b
Wow this hurts. Remind me to never review any of your PR’s
😢 1