Kotlin workshop

Overview

obsolete JetBrains project

This project is obsolete.

For the last version of Koans, check the course in the EduTools plugin or online version.

The task content can be found at https://github.com/Kotlin/kotlin-koans-edu.

Kotlin Koans

Kotlin Koans Workshop is a series of exercises to get you familiar with the Kotlin Syntax. Each exercise is created as a failing unit test and your job is to make it pass.

How to build and run tests

Working with the project using Intellij IDEA:
  1. Import the project as Gradle project.
  2. To build the project and run the tests use test task on the Gradle tool window (View | Tool Windows | Gradle).

Here https://www.jetbrains.com/help/idea/gradle.html#gradle_tasks you can read how to run Gradle task from the Gradle toolbar in IntelliJ IDEA.

Note that this project isn't intended to be used in Android Studio. If you want to solve koans in Android Studio, check the course in Android Studio with EduTools plugin installed https://github.com/kotlin/kotlin-koans#other-ways-to-solve-koans.

Working with the commandline

You can also build the project and run all tests in the terminal:

./gradlew test

But since running all the tests tend to take longer and the output can be cluttered, it's more ideal to run selected tests only:

$ ./gradlew test --tests i_*          # run tests in part 1
$ ./gradlew test --tests ii_*         # run tests in part 2
$ ./gradlew test --tests ii_*22*      # run test number 22 in part 2

How to check yourself

The repository has two branches, master which contains the exercises for you to do and resolutions which contains the resolved exercises. Make sure you don’t cheat!

How the tasks are organized

You have 42 tasks to do. Each task lives in its own function: from task0 to task41. For each task, there is an associated unit test that checks your solution.

You may navigate to the corresponding test automatically when you read the task. Open the source file with the task and use the action Navigate -> Test to open the test file. You may also use Navigate -> Test Subject for reversed navigation.

Individual tasks generally require you to change the function taskX by completely replacing the body of the function. Your goal is to solve the problem and allow the associated unit test to pass. If you run the unit test for a task that is not correct, the unit test results will be displayed. If you have not yet made any changes to a task, the exception will be thrown and the task's TODO message will be displayed.

In the first example, this means replacing the code

fun task0(): String {
    return todoTask0()
}

with the correct, meaningful code in order to solve the problem and allow the associated unit test to pass, such as:

fun task0() = "OK"

The resolutions branch contains all the solutions. It's a good idea to check the proposed solution after completing each task. Open the file with your solution, call the Compare with branch... action and choose the resolutions branch.
You can find here how to call an action.

Other ways to solve Koans

You can solve the similar tasks using Educational Plugin or in the browser:

The koans tasks for web-demo and educational plugin can be found here: https://github.com/Kotlin/kotlin-koans-edu

Comments
  • Error _15_OperatorsOverloading.kt

    Error _15_OperatorsOverloading.kt

    I'm a complete noob to Kotlin so I may be missing the point but the project doesn't build and currently errors in workshop-jb/src/ii_conventions/_15_OperatorsOverloading.kt

    opened by jchannon 16
  • Building and running tests with Maven

    Building and running tests with Maven

    Hi Friends!

    I dare to suggest this pom.xml which uses kotlin-maven-plugin to allow building the exercises and testing them with maven (as another option in addition to having idea / eclipse project files).

    opened by RodionGork 7
  • Cannot add extension with name 'kotlin', as there is an extension already registered with that name

    Cannot add extension with name 'kotlin', as there is an extension already registered with that name

    Just cloned and I get the following:

     ./gradlew test
    
    FAILURE: Build failed with an exception.
    
    * Where:
    Build file '/workspace/kotlin-koans/build.gradle' line: 15
    
    * What went wrong:
    A problem occurred evaluating root project 'kotlin-koans'.
    > Failed to apply plugin [id 'kotlin2js']
       > Cannot add extension with name 'kotlin', as there is an extension already registered with that name.
    
    * Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
    
    BUILD FAILED
    
    Total time: 0.762 secs
    
    opened by MattFriedman 5
  • NotImplementedException class override message field in Exception class

    NotImplementedException class override message field in Exception class

    Error:(6, 31) Kotlin: Accidental override: The following declarations have the same JVM signature (getMessage()Ljava/lang/String;):
        fun <get-message>(): kotlin.String
        fun getMessage(): kotlin.String?
    
    opened by MaXal 5
  • Doesn't work with Android Studio 2.0 preview

    Doesn't work with Android Studio 2.0 preview

    Figure there's a change you guys might want to investigate. I get 237 errors and failure at compilation, all along the lines of

    Error:(5, 1) Kotlin: 'public fun todoTask0(): kotlin.Nothing' is already defined in i_introduction._0_Hello_World.Hello

    Error:(7, 5) Kotlin: Redeclaration: idea

    This is happening with plugin version 1.0.0-beta-2429-IJ143-19

    Full output here: https://gist.github.com/hzsweers/7e341269f824c05232e8

    opened by ZacSweers 4
  • DateRange no longer works in forEach loop?

    DateRange no longer works in forEach loop?

    Was there a language change regarding using Ranges in a forEach loop? (I'm on kotlin 1.0 beta)

    In iii_conventions/_RangeTo.kt :

    for (date in firstDate..secondDate) {
           handler(date)
    }
    

    Will not compile for me. I am pretty sure I have my DateRange implemented correctly.

    Thank you! Loving Kotlin!

    opened by nicholasq 4
  • can't run tests

    can't run tests

    Just opening the project with the latest inteliJ community edition and hitting All Tests gives me 26 errors. Here is a screenshot of the first one. I have installed the kotlin plugin and ran my own 'hello world' project without issues.

    koanerror

    opened by nschwermann 4
  • Task 31 : resolution doesn't pass test

    Task 31 : resolution doesn't pass test

    Caution - I'm a newbie.

    for n31, my solution looks the same as the 'resolution' version, but doesn't pass the test I think because of the declarations of

    operator fun Invokable.invoke(): Nothing = todoTask31()
    fun Invokable.getNumberOfInvocations(): Nothing = todoTask31()
    

    in the test class.

    Note that the resolution doesn't pass either, I believe for the same reason? Can you give me a hint? My solution is

    class Invokable (private var count : Int = 0) {

     operator fun invoke() : Invokable {
         count++
         return this
     }
    
     fun getNumberOfInvocations() : Int = count
    

    }

    Apologies if I'm being an idiot.

    opened by geir 3
  • Q35 Reinstating removed tests, they were correct but...

    Q35 Reinstating removed tests, they were correct but...

    I think the logic for calculating dates from millis and vice versa was incorrect. Java.util.Calendar uses zero based months to keep you on your toes! Also Calendar.getInstance() will get the default Locale (and also timezone) so the toMillis conversions it produces will be adjusted accordingly.

    For example, Dates in December don't work with the old code! e.g. MyDate(2014, 12, 13) would create a date of: "2015-01-13" (Jan 13th 2015).

    The orignal asserts in the tests were removed here: https://github.com/Kotlin/kotlin-koans/commit/fdc9d249005cf68fd2f9326356aef534edbc648d, because they were not reliable because of the above reasons, but I think their original intentions remain valid, so I have reinstated them and amended the calendar logic to be compatible with zero-based months and always use UTC.

    The time in millis in the previous tests had an offset included, so when converted to UTC: 1392220800000 = 2014-02-12T16:00

    So I have changed it to: 1389571200000 = 2014-01-13T00:00

    This should yield succesfull test results when ran in different locales.

    opened by jaymoid 3
  • Rewrite MyDate.kt code using functional paradigm

    Rewrite MyDate.kt code using functional paradigm

    Hi,

    nowadays content of MyDate.kt is more objected-like and it does not look fancy (as it could):

    data class MyDate(val year: Int, val month: Int, val dayOfMonth: Int) : Comparable<MyDate>{
        override fun compareTo(other: MyDate): Int{
            if(year != other.year) return year - other.year
            if(month != other.month) return month - other.month
            return dayOfMonth - other.dayOfMonth
        }
    }
    
    operator fun MyDate.rangeTo(other: MyDate) = DateRange(this, other)
    

    I think that better purpose for this Kotlin programming language course would be rewrite existing code using a functional programming paradign. Here's my solution:

    data class MyDate(val year: Int, val month: Int, val dayOfMonth: Int) : Comparable<MyDate>{
        override fun compareTo(other: MyDate): Int = when {
            year != other.year -> year - other.year
            month != other.month -> month - other.month
            else -> dayOfMonth - other.dayOfMonth
        }
    }
    
    operator fun MyDate.rangeTo(other: MyDate) = DateRange(this, other)
    

    I must agree that change is pretty small, but as you provide in kotlin-koans course typical functional structures like lambdas or recursion, maybe it would be better to keep this course and its code functional, than messing it with 'java-like' code.

    Although, I found fun in rewriting every MyDate.kt instance and that was good additional trainign :-D

    Hope you would find useful. Cheers!

    opened by piotrek1543 3
  • Mavenize and remove Eclipse project files?

    Mavenize and remove Eclipse project files?

    Hey folks,

    Just getting into Kotlin and I had a hard time importing the koans into Intellij. Can we make it a Maven project and/or remove the editor settings (e.g., Eclipse files like .project)?

    opened by mrice 3
  • Use plugins edutools

    Use plugins edutools

    Environment:MacOS、Gradle 4.9 IDE:IntelliJ IDEA CE 2019.03 JDK : 1.8.0_111

    1. After join the course,always alert ”Kotlin Koans:failed“,don't have other info for this error 2.Click ”check“ in the task description,alert ”No tests have run“
    opened by Dwan-xie 4
  • Migrate to Gradle Kotlin DSL

    Migrate to Gradle Kotlin DSL

    Related to #173.

    • build.gradle file has been removed.
    • build.gradle.kts file has been added with content equivalent to the former build.gradle file.
    • ~Gradle wrapper has been upgraded to the current Gradle version 5.2.1 because of better and more stable support of Kotlin DSL.~
    opened by sw-samuraj 0
  • Build via Gradle Kotlin DSL

    Build via Gradle Kotlin DSL

    I'm just wondering - if the project is build by Gradle, why not to build it via Gradle Kotlin DSL? Wouldn't it be more appropriate?

    I've already did it in my fork of the project (see build.gradle.kts), so I can prepare a pull request.

    opened by sw-samuraj 0
Owner
Kotlin
Kotlin Tools and Libraries
Kotlin
CodeLab for the workshop: A Composable New World

A Composable New World! Compose is here! ?? I've created a codelab where you can follow step by step the development of android application using Comp

Carlos Mota 9 Nov 25, 2022
Repo: Programming problems with solutions in Kotlin to help avid Kotlin learners to get a strong hold on Kotlin programming.

Kotlin_practice_problems Repo: Programming problems with solutions in Kotlin to help avid Kotlin learners to get a strong hold on Kotlin programming.

Aman 0 Oct 14, 2021
Mocking for Kotlin/Native and Kotlin Multiplatform using the Kotlin Symbol Processing API (KSP)

Mockative Mocking for Kotlin/Native and Kotlin Multiplatform using the Kotlin Symbol Processing API (KSP). Installation Mockative uses KSP to generate

Mockative 121 Dec 26, 2022
Kotlin-oop - Repositório criado para ser utilizado pelo projeto de Kotlin OOP desenvolvido em Kotlin nas aulas feitas através da plataforma Alura.

Projeto React OOP Repositório criado para ser utilizado pelo projeto de Kotlin OOP desenvolvido em Kotlin nas aulas feitas através da plataforma Alura

Marcos Felipe 1 Jan 5, 2022
Kotlin-koans - Kotlin Koans are a series of exercises to get you familiar with the Kotlin Syntax

kotlin-koans-edu Kotlin Koans are a series of exercises to get you familiar with

null 1 Jan 11, 2022
Kotlin TodoMVC – full-stack Kotlin application demo

Kotlin full stack TodoMVC This project is an example implementation of the TodoMVC app written in Kotlin. More specifically, it's the Kotlin port of t

Gyula Voros 22 Oct 3, 2022
Integration Testing Kotlin Multiplatform Kata for Kotlin Developers. The main goal is to practice integration testing using Ktor and Ktor Client Mock

This kata is a Kotlin multiplatform version of the kata KataTODOApiClientKotlin of Karumi. We are here to practice integration testing using HTTP stub

Jorge Sánchez Fernández 29 Oct 3, 2022
Small kotlin library for persisting _single instances_ of kotlin data classes

PerSista Small library for persisting single instances of kotlin data classes. NB: PerSista uses typeOf() internally which is marked as @ExperimentalS

Eric Donovan 5 Nov 13, 2022
Kotlin Leaning Notes from Udacity Course | Kotlin Bootcamp for Programmers by Google

Kotlin Beginners Notes These are all personal notes taken from the Udacity Course (ud9011) of Kotlin Bootcamp for Programmers by Google as well as oth

Süha Tanrıverdi 34 Dec 10, 2022
Saga pattern implementation in Kotlin build in top of Kotlin's Coroutines.

Module Saga Website can be found here Add in build.gradle.kts repositories { mavenCentral() } dependencies { implementation("io.github.nomisr

Simon Vergauwen 50 Dec 30, 2022
Kotlin microservices with REST, and gRPC using BFF pattern. This repository contains backend services. Everything is dockerized and ready to "Go" actually "Kotlin" :-)

Microservices Kotlin gRPC Deployed in EC2, Check it out! This repo contains microservices written in Kotlin with BFF pattern for performing CRUD opera

Oguzhan 18 Apr 21, 2022
A sample skeleton backend app built using Spring Boot kotlin, Expedia Kotlin Graphql, Reactive Web that can be deployed to Google App Engine Flexible environmennt

spring-kotlin-gql-gae This is a sample skeleton of a backend app that was built using: Spring Boot(Kotlin) Reactive Web Sprinng Data R2DBC with MYSQL

Dario Mungoi 7 Sep 17, 2022
Modular Android architecture which showcase Kotlin, MVVM, Navigation, Hilt, Coroutines, Jetpack compose, Retrofit, Unit test and Kotlin Gradle DSL.

SampleCompose Modular Android architecture which showcase Kotlin, MVVM, Navigation, Hilt, Coroutines, Jetpack compose, Retrofit, Unit test and Kotlin

Mohammadali Rezaei 7 Nov 28, 2022
Learn-kotlin - Learning more about Kotlin in various content

Kotlin study roadmap https://kotlinlang.org/docs/reference/ Getting Started Basi

Danilo Silva 0 Jan 7, 2022
Mis experimentos con Kotlin para JetBrains Academy, certificación de Kotlin donde voy resolviendo proyectos de evaluación y haciendo actividades de cada tema.

Kotlin Academy Mis experimentos con Kotlin para JetBrains donde voy resolviendo proyectos de evaluación y haciendo actividades de cada tema. Acerca de

José Luis González Sánchez 1 Jan 10, 2022
Repositório criado para ser utilizado pelo projeto de Kotlin Collections desenvolvido em Kotlin nas aulas feitas através da plataforma Alura.

Projeto Kotlin Collections Repositório criado para ser utilizado pelo projeto de Kotlin Collections desenvolvido em Kotlin nas aulas feitas através da

Marcos Felipe 1 Jan 17, 2022
Kotlin-GraphQL-Apollo - Sencillo cliente para consumir una API GraphQL con Apollo usando Kotlin

Kotlin GraphQL Apollo Sencillo cliente para consumir una API GraphQL con Apollo

José Luis González Sánchez 2 Jan 25, 2022
DS-for-Kotlin - Some classic data sturctures write in kotlin for fun

DS-for-Kotlin Just write some classic data structure by kotlin during my leisure

ccyyxx 2 Jan 30, 2022
Account-hexa-service-kotlin - Microservice with Kotlin using Hexagonal architecture

Microservice Construindo microservice de conta para fins Didáticos. Objetivos Cr

Adriano Marcião 1 Jan 30, 2022