Function Fluency with infix
Explore how infix notation in Kotlin lets you write cleaner, more expressive code by omitting dots and parentheses for single-parameter functions. Understand how this technique improves fluency and readability, making your Kotlin functions feel more natural and less noisy.
We'll cover the following...
The infix notation
Dots and parenthesis are common in code we write, but on many occasions leaving those out can make the code less noisy and easier to follow. For example, the following is familiar code in Java:
//Java
if(obj instanceof String) {
Imagine Java had insisted that we write if(obj.instanceOf(String)) {—what a clutter that would have been. Instead, we used a nice syntax if(obj instanceof String) {—that’s much easier to read, and it uses what is called the infix notation, where an operator is infixed or implanted in the middle of its operands. That syntax is ...