following up on #beginners > this should never happen - what if we had this?
Result.orElse : Result ok err, (err -> ok) -> ok
then you could do:
|> Result.orElse \_ -> crash "blah"
what I like about this compared to a function like unwrap (which I'm explicitly opposed to ever adding to Result) is that you still have the crash keyword explicitly in your code, so you can see that a crash is possible here. It would just be more pipeline-friendly than having to write out the when.
I like that a lot. Then people can stop writing unwrap helpers and still have something explicit inline.
That sounds great
unwrap
There’s also expect in rust’s Result
It would be great to have smth like either of that at your fingertips. The very first thing I implemented in roc is listGetUnsafe (don’t know why it wasn’t the unwrap)
What if crash could print anything with Inspect like dbg? Then you could do:
|> Result.orElse crash
You’d get the error printed and a stack trace
hm I'd say let's try it as-is and revisit that later :big_smile:
Am I right in assuming that you can't put crash in library code or pure roc or something, it's not like haskell's fail wherever you like error? I just don't want orElse, crash to be the roc "how do I get rid of result?"
Am I right in assuming that you can't put crash in library code
It's something we've discussed in the past but it is still allowed now.
Last updated: Jun 16 2026 at 16:19 UTC