Series
Kotlin Koans BR
A hands-on tour of Kotlin's core language features — from string templates to sealed classes and smart casts — one short, focused exercise at a time.
13 parts 59 min read Beginner Source code RSS
Start the series →What you'll learn
- Read and write idiomatic Kotlin with confidence
- Use nullable types, smart casts and sealed classes safely
- Apply extension functions, lambdas and data classes in real code
In this series
-
Part 1 5 min read
Kotlin Koans BR: Hello, world!
Change the code so that the start function returns the string "OK".
-
Part 2 2 min read
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 4 min read
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 2 min read
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 2 min read
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 5 min read
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 2 min read
Kotlin Koans BR: The "nothing" type (Nothing)
Specify the Nothing return type for the failWithWrongAge function.
-
Part 8 3 min read
Kotlin Koans BR: Lambdas
Pass a lambda to the any function to check whether the collection contains an even number.
-
Part 9 9 min read
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 7 min read
Kotlin Koans BR: Smart casts
Rewrite the given code using Kotlin smart casts and the when expression.
-
Part 11 12 min read
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 2 min read
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 4 min read
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.