I’m just getting started with learning Kotlin and ...
# functional
I’m just getting started with learning Kotlin and at the same time I’m trying to advance my functional programming understanding/skills. My background is in web development with JS (using functional/declarative libraries like Ramda and XState). Is there a recommend learning path? Books, tutorials, videos, etc. Thanks!
Oh that is a hard one. Kotlin has one novel concept over JS, which are scopes.
Scopes in JS could be broken, if you remember you can reference
in any function and because of the lack of types it could call anything wherever at the callsite.
Kotlin fixes this by typing the
that you refer to. This is used for both extension functions and lambdas.
that you'll need to read some info off the internet for. There are a few explaining examples using helper functions like
The rest is your standard OOP fare: classes, inheritance, special syntax for fields and constructors, patches for mutability such as lateinit...
You'll have to engage that part due to JVM integrations
the bits that are somewhat different are first class
, which is JS's equivalent of...well, an object stored in a variable
object Bla {... }
in Kotlin is
const Bla: Bla = {... }
in JS
class Bla { object Ble { ... } } could be Bla.prototype.Ble = { ... }
the other one is sealed classes. In Typescript you have unions, in Kotlin you use inheritance to simulate unions
"but what if I want a union of something I don't define" -> you wrap it in a class
last one, for class wrapping or your network POJOs you use
data class
. It comes with some things you'd expect to see by default in any class, like structural equality and stable hashes.
those are hints to move to kotlin in general
once you're familiar, the FP bits are not much different from async/await and any FP lib you've used before
map, flatMap, filter...you know the works
the arrow-kt.io docs could help you go through these, and there are links to books and talks from people who've taken this path before
@pakoito Amazing! Thanks a ton for these tips and explanations! A lot of the resources are more focused on explaining Kotlin to Java devs (for obvious reasons) so it’s super helpful to hear about Kotlin from someone who is familiar with JS. So I appreciate the time you put into these comments! 🙌 Arrow looks super interesting, definitely going to try it out! arrow