KotlinConf’23 — Kotlin & Functional Programming: pick the best, skip the rest by Urs Peter

Matthew Dolan
2 min readApr 14, 2023
Download slides

I recently had the pleasure of listening to Urs Peter’s talk on Kotlin & Functional. The speaker gave a great, simple summary of what a Monad is and how it works.

In essence:

  • a Monoid is combinable (plus) and has an identity (empty) element which when combined with another value returns that other value.
  • a Functor is mappable (map)
  • a Monad is composable (flatMap)

The talk then went on to discuss some common monads, such as Collections and Optional.

The highlight of the talk for me was when the speaker talked about cherry-picking the best features between Kotlin and Monads (using the Arrow framework).

Use Monads selectively where needed and useful.

  • Why use a Monad to replace try-catch blocks for the 95% of use cases? Let exceptions bubble up to a GlobalExceptionHandler.
  • For the other 5%, where we’re typically recovering in our service, prefer Either<A,B> over Result as it makes the contract explicit with easy access to the error reply.
  • Prevent tedious null checks with Arrow’s nullable{ } comprehension.
  • With deeply nested data structures where you want to change something at the leaf level, use Arrow Optics instead of nested copy calls.

While I enjoyed the talk, I would have loved to hear more best features.

You can find my thoughts on more KotlinConf’23 talks at KotlinConf’23. Please let me know your thoughts.

Join medium to read all of my articles or subscribe for e-mail updates.

--

--

Matthew Dolan

Matt Dolan has been eating doughnuts and developing with Android since the dark days of v1.6.