https://kotlinlang.org logo
Title
a

Alejandro Serrano Mena

03/03/2023, 8:28 AM
hi! we’ve just published a blog post about a particular style of programming in Kotlin, heavily influenced by functional programming ideas but still Kotlin-idiomatic. I hope you enjoy it! https://xebia.com/blog/the-suspend-receivers-style-in-kotlin/
y

Youssef Shoaib [MOD]

03/03/2023, 11:39 AM
At a conceptual level, you can think of
Continuation<A>
as simply a function
(A) -> Unit
. This means the caller can change how the function "returns," but changing the continuation passed as parameter
k
.
I believe that's meant to say by changing the continuation not but changing the continuation
Not trying to nitpick or anything, it just confused me a bit while reading lol
a

Alejandro Serrano Mena

03/03/2023, 11:51 AM
oh, thanks for the catch 🙂
n

Norbi

03/04/2023, 8:08 PM
great article, thanks (although it is for advanced Kotlin users imho)
One more question: could someone please explain why continuations are needed at all to implement these features?
a

Alejandro Serrano Mena

03/07/2023, 9:57 AM
continuations are what lays below the
suspend
mechanism
the important part here is that continuations give you power about how the code they live in is executed
for example, you can decide that if you call a certain function, nothing else in the block ought to be executed
n

Norbi

03/07/2023, 10:05 AM
you can decide that if you call a certain function, nothing else in the block ought to be executed
Hmmm, this must be the key reason for using them. But cannot this mechanism also be implemented by using non-
suspend
functions and throwing-catching exceptions?
a

Alejandro Serrano Mena

03/07/2023, 10:48 AM
the key difference is that with exceptions you can decide to break execution at some point, but you cannot do things like “pause execution, do a bit on the side, then resume where it was before”, which is something you can do with continuations (because you decide at which point tou call
resume
)
n

Norbi

03/07/2023, 4:26 PM
you cannot do things like “pause execution, do a bit on the side, then resume where it was before”,
One last question: then how is it possible to have an
eagerEffect {}
as well in Arrow? Does it have some serious limitations compared to
effect {}
?