I thought some people here might find this valuable / entertaining / challenging.
I teach a sophomore CS class at Rice University (http://comp215.blogs.rice.edu/) which introduces Java8 and does everything in a functional style. For fun, I decided to try porting some of the basics of my functional list support library to Kotlin. I’ve posted the results on GitHub and I thought I’d list my obervations for everybody here to chew on.
You can see all of my notes here:
In a nutshell, I really enjoyed playing with Kotlin. The ability to write extension functions, in particular, really cleans up the mess that I had to do in Java8 to write the same things, plus the fact that you have “real” lambdas means that you have to spend a whole lot less time worrying about <in T> vs. <out T> than you do in Java8, since you don’t need to declare anything awful like Function<? super T, ? extends T> when all you want is (T)->T. I also enjoyed taking everything that I’d previously done with Java8’s Optional type and redoing it with Kotlin’s more precise handling of null than you’d ever get away with in Java (at least, not without tons of annotations or a static checker).
There are a bunch of places where Kotlin is still showing its beta-ness. In particular, if you want to have a singleton generic empty-list, in Java you would take advantage of @SurpressWarnings(“unchecked”) and Java’s type erasure to let you have one instance of the empty-list for all types. I transliterated this concept to Kotlin and it gives some scary warnings (“This cast can never succeed”), but in fact they succeed just fine.
This code isn’t something I intend anybody to adopt yet. It’s just my first crack at writing something non-trivial in Kotlin. I’d appreciate feedback from people here about whether this code is written “properly” for Kotlin and/or how it could be tweaked to compile without any warning messages.