Everything else is just a tool to model your domain in a way that’s easier to read and reason about, and to produce much shorter code. Interfaces define module boundaries and can be mocked to enable simpler testing. Through classes, objects, and data structures, you can model your domain entities. Enums make a list of limited options crystal clear. Extensions allow you to add functionality to existing types, without having access to their original source code, giving advantage of better logic structure. With generics, you can write universal code, promoting reuse. And overloaded operators give that extra edge to common operations that benefit from succinct, crisp syntax.

Operator overloading

You can customize operators for your custom types, however you cannot create new ones. With infix notation, you can write functions that appear as new operators. There’s also an operation called destructuring, that deserves a special attention.

At the end of the day, it’s all syntax sugar, albeit quite convenient one.

Infix notation

infix fun Int.pow(exponent: Int) =
  (1..exponent).fold(1) { acc, _ -> acc * this }

2 pow 4

[--]