Let’s say it as it is: there’s no language-level support for typeclasses in Kotlin. Dome folks managed to implement something that resembles typeclasses by creatively abusing context receivers (fair play to them) but this is not idiomatic Kotlin. And I only ever see this kind of thing coming from overly enthusiastic folks with a Scala background 🤣.
Let's look at how a typeclass can be implemented in Kotlin with context parameters, and how you can achieve the same result in Scala. #kotlin #scala https://cdn.nostrcheck.me/f5c3f597f754f534d47b0be2b9afe263894ecdad3d639453c4abc31f40db2c23/86d6275fbda583d56ad815f19dcee2ed07d3a4da871b7b39ece51779bd19cbf6.webp https://cdn.nostrcheck.me/f5c3f597f754f534d47b0be2b9afe263894ecdad3d639453c4abc31f40db2c23/0fff0f2df08c1df938f99a3de83d027ad0267fc58beeebf128357bdbbcf57ae3.webp
Discussion
At first, it was like "I want to write Haskell, but I'm forced to use JVM." Now it's like "I want to write Scala, but I'm forced to use Kotlin" 😂