Pattern matching in Kotlin

Ten interesting features from various modern languages

Kasper Peulen
2 min readNov 9, 2017

--

Lately I have been studying some modern languages, such as Reason, Swift, Kotlin and Dart. I got excited by many of the features they offer. Many of those features I had never read or heard of before. Today, I want to share with you the 10 features that I found most interesting.

I hope that in the coming years, features like these will become more widely adopted, also in older languages, such as Javascript, PHP, Java and Python. As many of us programmers have to work with those languages every day at work, I would love it if also those languages keep evolving.

Click on any of the Read more… links below to go to the documentation of the language. Often there is some playground that you can immediately start hacking with!

#1 Pipeline operator

I couldn’t find any official documentation from Reason, but it seems to work similar as this ECMAScript proposal. You can try it out in a playground here.

#2 Pattern matching

Read more…

Read more…

#3 Reactive (Rx) programming build in the language

Read more…

#4 Implicit name (using “it”) of a single parameter in a lambda function

Read more…

#5 Destructuring

Read more…

#6 Cascade operator

Read more…

#7 If expressions

Read more…

#8 Try expressions

Read more…

#9 Automatic currying

Read more…

#10 Method extensions

Read more…

I hope you have learned something new. Happy coding :)

Update: All the examples above are from Reason, Swift, Kotlin and Dart. However, many of the ideas above can already be found in much older languages such as Lisp (1958), Smalltalk (1972), Objective-C (1984), Haskell (1990), OCaml (1996) and many more. So while the examples are from “modern” languages, the ideas in this article are actually very “old”. (*)

You could say that those “modern” languages try to popularise old ideas. They put the idea in a different more common syntax while also leveraging older ecosystems. All the languages in this article use the popular C-style syntax. For example, Reason is OCaml in a C-style/Javascript-style syntax while also leveraging the JavaScript and OCaml ecosystem and Dart is heavily influenced by Smalltalk and leverages the Javascript ecosystem.

--

--

Kasper Peulen
Kasper Peulen

Written by Kasper Peulen

Programmer, fullstack, loves learning new things.

Responses (39)