Learning Kotlin: Named Arguments

Submitted by Robert MacLean on Thu, 06/14/2018 - 09:00
**More Information** * [Code for the 3rd Koan can be found here](https://github.com/Kotlin/kotlin-koans/blob/master/src/i_introduction/_2_Named_Arguments/n02NamedArguments.kt). * This is the 3rd post in a multipart series. If you want to read more, see our [series index](/learning-kotlin-introduction) On to our third exercise and definitely, the difficulty curve has lowered again (or should it be [steep](https://www.visualthesaurus.com/cm/wordroutes/a-steep-learning-curve-for-downton-abbey/)) as we have a simple lesson - how to use named arguments. Not only is an example for it provided for how named arguments work: fun usage() {     // named arguments     bar(1, b = false) } We also get an example of default values for arguments fun bar(i: Int, s: String = "", b: Boolean = true) {} The problem we need to solve itself is simple too, >Print out the collection contents surrounded by curly braces using the library function 'joinToString'. Specify only 'prefix' and 'postfix' arguments. Which has this answer: fun task2(collection: Collection<Int>): String {     return collection.joinToString(prefix = "{", postfix = "}") } Not much to add to this lesson unfortunately.