You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{-| Lazy version of `Result.fromMaybe`
Only calculates the error case on Nothing
maybe
|> Result.fromMaybe (\() -> Debug.todo "expensive calcuation")
-}
fromMaybeLazy : (() -> x) -> Maybe a -> Result x a
fromMaybeLazy fErr maybe =
case maybe of
Just a ->
Ok a
Nothing ->
fErr () |> Err
I used Result.fromMaybe in my code and was computing a complicated error message from a long list, didn't realize the error case was evaluated for every value even if there were no errors. I then needed the lazy version shown here.
The text was updated successfully, but these errors were encountered:
Could we add a new function fromMaybeLazy.
I used Result.fromMaybe in my code and was computing a complicated error message from a long list, didn't realize the error case was evaluated for every value even if there were no errors. I then needed the lazy version shown here.
The text was updated successfully, but these errors were encountered: