This project contains the basis for starting with this workshop.
There is also a presentation.
Firtly pull the content of this repository to your local machine.
Then run the following command on your local machine to check if you're ready to go.
./gradlew build
So, if the above command doesn't work, then there is most likely something missing. Please check the installation instructions for Kotlin.
Exercise 1 introduces the syntax of functions in Kotlin
Exercise 2 goes into the higher-order functions and composition
Exercise 3 introduces Arrow
So there are a few ways that you can test your code:
- using your IDE
- building a jar, and running it
- using the Kotlin REPL
Some, if not all nowadays, IDEs allow you run code directly from within the
workspace. For instance the IntelliJ IDEA shows a play button next to any code
that it knows how to execute ( main
methods for instance ). So, that allows
you to easilly test what you have created.
The simplest way to create a jar for testing, is by using the command-line.
To create a jar, make sure you know the files that you want to include. For instance to build a jar and run it for exercise 1, use this command;
# use the kotlin compiler to build files Books.kt and Exercise1.kt into a Jar
kotlinc src/main/kotlin/Books.kt src/main/kotlin/Exercise1.kt -include-runtime -d exercise1.jar
# execute the jar, and see the result
java -jar exercise1.jar
The Kotlin REPL allows you to load files and invoke functions directly. This is
an effective way for testing your code without having to rebuild the jar. For
example running a main
method for exercise 1 can be done
like so:
# ensure you are in the src/main/kotlin dir
cd src/main/kotlin
# start the Kotlin REPL
kotlinc-jvm
# within the Kotlin REPL, load required files, and execute main function
>>> :load Books.kt
>>> :load Exercise1.kt
>>> main()
Make sure you reload the files that have changed if you have made changes and want to test again!