Robert MacLean
14 June 2018
**More Information**
- Code for the 3rd Koan can be found here.
- This is the 3rd post in a multipart series.
If you want to read more, see our series index
On to our third exercise and definitely, the difficulty curve has lowered again (or should it be steep) 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): String {
return collection.joinToString(prefix = "{", postfix = "}")
}
Not much to add to this lesson unfortunately.