Stream: beginners

Topic: Error propagation with back passing


view this post on Zulip Brian Teague (Feb 04 2024 at 05:28):

Not sure if this would be related to Result.orElse, but does Roc have error propagation, so you can write waterfall style code for Ok backpass unrwapped and return an Err otherwise?

Something like this?

errorPropagation =
   a <- Num.divChecked 2 0 |> Result.next
   b = a - 1
   c <- Num.divChecked 3 b |> Result.next

Would fast fail with Err [divideByZero]

errorPropagation =
   a <- Num.divChecked 2 2 |> Result.next
   b = a - 1
   c <- Num.divChecked 3 b |> Result.next

Would first succeed with a, but then fail with Err [divideByZero]

errorPropagation =
   a <- Num.divChecked 4 2 |> Result.next
   b = a - 1
   c <- Num.divChecked 3 b |> Result.next

Would succeed with Ok 3

view this post on Zulip Sven van Caem (Feb 04 2024 at 06:55):

I believe you're looking for Result.try! It works exactly like you describe.


Last updated: Jul 06 2025 at 12:14 UTC