Learning Kotlin: Named Arguments

Note

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 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 the '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.