
Series
Kotlin Koans BR
13 parts Source code
In this series
-
Part 1
Kotlin Koans BR: Hello, world!
Change the code so that the start function returns the string "OK".
-
Part 2
Kotlin Koans BR: Named arguments
Make the joinOptions() function return the list in JSON format (for example, [a, b, c]) by specifying only two arguments.
-
Part 3
Kotlin Koans BR: Default arguments
Imagine you have several overloads of foo() in your favorite language. You can replace them all with a single function in Kotlin.
-
Part 4
Kotlin Koans BR: Triple-quoted strings
Swap the trimIndent call for trimMargin, setting # as the prefix value, so the resulting string no longer contains the prefix character.
-
Part 5
Kotlin Koans BR: String Templates
The pattern below matches a date in the format 13.06.1992 (two digits, a dot, two digits, a dot, four digits):
-
Part 6
Kotlin Koans BR: Nullable types
Rewrite the following code so that it uses only a single if expression, and learn how Kotlin handles nullable types safely.
-
Part 7
Kotlin Koans BR: The "nothing" type (Nothing)
Specify the Nothing return type for the failWithWrongAge function.
-
Part 8
Kotlin Koans BR: Lambdas
Pass a lambda to the any function to check whether the collection contains an even number.
-
Part 9
Kotlin Koans BR: Data Classes
Rewrite the following code in Kotlin, then add the data modifier. A beginner-friendly look at Kotlin classes and data classes.
-
Part 10
Kotlin Koans BR: Smart casts
Rewrite the given code using Kotlin smart casts and the when expression.
-
Part 11
Kotlin Koans BR: Sealed Classes
Reuse your solution from the previous task, but replace the interface with a sealed interface. That way you no longer need the else branch in the when expression.
-
Part 12
Kotlin Koans BR: Import alias
When importing a class or function, you can give it a different name by adding as NewName after the import directive. This can be useful when…
-
Part 13
Kotlin Koans BR: Extension functions and properties
Implement the extension functions Int.r() and Pair.r() so they convert an Int and a Pair into a RationalNumber.