Block-form pattern-match handler at the call site #152
Open
serradura wants to merge 1 commit into
Open
Conversation
Micro::Case::Result::Wrapper#success / #failure now accept *types so a
single branch can match multiple result types (a strict superset of the
prior single-optional-type form). #success / #failure / #unknown also
dispatch on block.arity: a 2-arity block (|data, type|) receives the
result's data hash and type symbol; 1-arity (and 0/-1/-2) keep
receiving the full Result, so every existing call site is unchanged.
Together these unlock the motivating call site:
MyCase.call(input) do |on|
on.success(:ok, :created) { |data, type| ... }
on.failure { |data, type| ... }
on.unknown { |result| ... }
end
No new public constants and no new exceptions on previously-silent
paths. Exhaustiveness (raise when no branch matched and no `unknown`
was declared) is intentionally deferred to a follow-up gated by an
opt-in, to preserve the silent-Kind::Undefined fallback.
Closes #4.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Micro::Case::Result::Wrapper#success/#failurenow accept*types(splat) — a strict superset of the prior single-optional-typeform, so one branch can match multiple result types (on.success(:ok, :created) { ... }).#success/#failure/#unknowndispatch onblock.arity: 2-arity blocks receive(data, type); 1-arity (and 0/-1/-2) keep receiving the fullResult. Every existing call site is unchanged byte-for-byte.unknownwas declared) is intentionally deferred to a follow-up gated by an opt-in, so the current silent-Kind::Undefinedfallback stays observable.CHANGELOG.mdrecords the change under## [Unreleased]— version bump intentionally skipped here (per the author's instruction); the release commit can roll this into the next minor.README.mdandREADME.pt-BR.mdget a new Block-form handler at the call site / Handler em forma de bloco no local da chamada subsection under "Working with results", in lockstep.Test plan
bundle exec rake test— 814 runs, 8229 assertions, 0 failuresENABLE_TRANSITIONS=true bundle exec rake test— greenENABLE_TRANSITIONS=false bundle exec rake test— greentest/micro/case/result/wrapper_test.rb— 19 cases covering:success,failure,unknown*typessplat matching onsuccessandfailure(matches when any listed type matches; skips when none do)(data, type)blocks onsuccess,failure,unknownunknownstill firessuccesswins; later ones skipped)Micro::Case.callblock-form returnswrapper.output; non-block returns theResultunknowndoes not run when asuccess/failurealready matchedENABLE_TRANSITIONS=true|falseaxis🤖 Generated with Claude Code