Skip to content

Result: map_err and deconstruct#11

Merged
nz merged 2 commits into
mainfrom
feat/result-map-err-deconstruct
Apr 22, 2026
Merged

Result: map_err and deconstruct#11
nz merged 2 commits into
mainfrom
feat/result-map-err-deconstruct

Conversation

@nz

@nz nz commented Apr 22, 2026

Copy link
Copy Markdown
Member

Surprised I went this long without Result#map_err, I really need to make a full checklist of Result methods and see what else may be missing.

Also deconstruct is pretty useful for pattern-matching on Result. Because Ruby has Exceptions, but exception-handling is optional, I find it fits the job that Errgonomic is doing to rescue certain (domain-applicable) exceptions, and return them with the Error side of a Result. Using deconstruct and Ruby pattern matching gives me a reasonable approximation of matching an enum in Rust.

result = Errgonomic::Result::Err.new(StandardError.new("nope"))
case result
in Errgonomic::Result::Ok, value
  "Measurement is #{value}"
in Errgonomic::Result::Err, String => msg
  "Measurement failed with a message: #{msg}"
in Errgonomic::Result::Err, Exception => e
  "Measurement produced an exception -- #{e.class}: #{e}"
end # => "Measurement produced an exception -- StandardError: nope"

So far I think this is more helpful than it is uncanny valley. But this whole gem kind of flirts with that space.

@nz nz merged commit 63d6f57 into main Apr 22, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants