Skip to content
← All posts

Series

Kotlin Koans BR

13 parts Source code

In this series

  1. Part 1

    Kotlin Koans BR: Hello, world!

    Change the code so that the start function returns the string "OK".

  2. 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.

  3. 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.

  4. 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.

  5. 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):

  6. 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.

  7. Part 7

    Kotlin Koans BR: The "nothing" type (Nothing)

    Specify the Nothing return type for the failWithWrongAge function.

  8. Part 8

    Kotlin Koans BR: Lambdas

    Pass a lambda to the any function to check whether the collection contains an even number.

  9. 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.

  10. Part 10

    Kotlin Koans BR: Smart casts

    Rewrite the given code using Kotlin smart casts and the when expression.

  11. 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.

  12. 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…

  13. 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.