Total beginner here :sweat_smile:. I am trying to have a function which leverages Result
but in the end I'm trying to "masquerade" a DivByZero
with a more domain-oriented Tag (in this example: NotEnoughItems
). I think this is a batter practice rather than just kicking a DivByZero to the consumer. However I am struggling a bit when trying to make computationWhichWoudlntWorkIfListIsEmpty
into a .. "lazy" ? Or is it the case then in Roc, this value would only be evaluated if the if
branch got to that point, and therefore I wouldn't need the = \_ ->
syntax?
outerFunction : List (Num a) -> Result (Num a) [NotEnoughItems, SomeOtherError]
outerFunction = \items ->
computationWhichWoudlntWorkIfListIsEmpty = \_ -> # ❓❓
# Here I can safely assume the list isn't empty. If the list were empty, this would result in an `Err DivByZero`
Err SomeOtherError
if List.len items < 1 then
Err NotEnoughItems
else
computationWhichWoudlntWorkIfListIsEmpty () # ❓❓
The general syntax is to pass in an empty record
NoArgFunc {}
You do need it as a function or would need to define it in the if branch. Roc is not lazy.
Thank you for the reply. Okay, the empty record kind of makes sense
Fábio Beirão has marked this topic as resolved.
Last updated: Jul 26 2025 at 12:14 UTC