Tips for golfing in Kotlin Given Google's recent announcement of official Kotlin support for Android development, I thought it might be timely to poll the community for some awesome golfing tips for this relatively new JVM language.

Kotlin includes a unique combination of features among it's JVM siblings which makes it potentially attractive for golfing:


operator overloading
local, infix, and static extension functions
smart casts
Groovy-style type-safe builders
type aliases
ranges
an extensive functional collections package
scripting support


So, how do I squeeze the last few bytes out of my Kotlin program? One tip per answer, please.
Use + instead of toString

As one might expect, String overloads the + operator for string concatenation, like so.

print("Hel" + "lo")


However, checking the docs tells us that it accepts Any?, not just String. As stated:


  Returns a string obtained by concatenating this string with the string representation of the given other object.


In other words, String + anything makes sure to call .toString() on the right hand side before concatenating. This allows us to shorten it.toString() to ""+it, a massive 8 byte savings at best and 6 bytes at worst.



Use fold instead of joinToString

Related to the above, if you're calling map and then joinToString, you can shorten that by using fold instead.

list.map{it.repeat(3)}.joinToString("")
list.fold(""){a,v-&gt;a+v.repeat(3)}