Result fold's in gleam #3966
-
Hey, I am a newbie in gleam, i was trying to solve a scenario where i have a result object and based on whether the result is Ok or Error, i would perform a addition operation, below is the snippet of code
i was looking into how to change the case dict.get into a piping operation using the result library, something like
but i was facing issues trying to figure out how to perform the operation during the error case when the key doesnt exist in the Dict. I tried using map_error, but that wraps the output i want inside the Error() and not what i want. This is what i tried
My question is if there is any way to write the above like Please let me know if there is a way to achieve what i want |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
I would write it with a case expression, but without |
Beta Was this translation helpful? Give feedback.
You could use
map
withunwrap
perhaps.