How do you write about coroutines without writing ...
# feed
s
How do you write about coroutines without writing about coroutines? 😄 I made a list of all the ways I can think of to use
suspend
in other places besides an ordinary coroutine. I just know there are tons more, though, so I'm really interested to hear what other uses people have found. https://sam-cooper.medium.com/suspending-kotlin-beyond-coroutines-4c97543b9782
y
You could implement monad comprehensions and even effect handlers ;)
🤯 1
very nice 1
a
numbers 6 - there's a good video about reimplementing coroutines

https://www.youtube.com/watch?v=2SpeJj7BUs4

🤩 1
🙏 1
c
I don't have code publicly available, but I have a small DSL for writing state machines in imperative style Instead of
Copy code
class StateMachine {
    private var currentState = State.Initial

    fun next(action: Action) {
        when (action) {
            Action.A ->
            Action.B ->
        }
    }  
}
you can write
Copy code
val StateMachine = stateMachine {
    waitFor(Action.A)
    // …

    select {
        onAction(Action.A) -> …
        onAction(Action.B) -> …
    }
}
It helps a lot with understanding complex state machines when some actions are allowed in only some situations.
👍 1
s
At this rate I'm going to have to write a part two of the article 😄
😁 1
These are all really cool!