Hi! I’m trying to build a CLI script with Roc, struggling a little bit but getting somewhere! The main difficulty is around tasks I guess. Currently my issue is the following. I have this functioning code at the end of my main loop (passed to Task.loop):
when (oldState, newState) is
(DirtySince _, Clean) ->
Stdout.line! "no more changes!"
Sleep.millis! pollDelayInMillis
Task.ok (Step newState)
_ ->
Stdout.line! (stateToStr newState)
Sleep.millis! pollDelayInMillis
Task.ok (Step newState)
How can I move the last two lines of each branch (Sleep.millis and Task.ok) in a single place?
I would add a function like below and call it from both branches;
sleepOk = \sleepMillis, newState ->
Sleep.millis! sleepMillis
Task.ok (Step newState)
Does that work for you?
Oh ok makes sense! That works, I thought there would be a more clever function but that’s ok.
Thanks!
Sylvain Brunerie has marked this topic as resolved.
Last updated: Jul 06 2025 at 12:14 UTC