-
-
Notifications
You must be signed in to change notification settings - Fork 129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't extract wrapped array through pattern-matching #173
Comments
It is intentional, it's also documented in the docs. I don't remember the details but I think it's related to using PM in the following scenario: case Failure[:error, 'oops']
in Failure[:error, message]
message # => 'oops'
end Again, I don't remember details but I think removing the branch will force using |
Thanks for getting back, @flash-gordon. I'm failing to understand the inconsistency with the constructor, shouldn't we use |
IIRC the shorthand |
I see. Do you see it as something we could change in a major release (including the constructor)? Surely not the end of the world, but it's a pity we can't blindly use pattern matching for any kind of wrapped value and need to rely on not-as-pure methods like |
For context, I'd like to use it for the code at dry-rb/dry-operation#6 |
Not likely at this point. I have hundreds if not thousands of usage in my codebase alone, changing them all would be a time-consuming task. On the other hand, I paid attention to this caveat, and so far I've got only a couple of questions about this documented behavior. How did you come across this issue? |
While working on
|
Ah, I see. I think it's ok not to use PM here, it's library code so matching cases it not as important. Moreover, calling |
Describe the bug
When a right-biased type is wrapping an array value, it's not possible to unwrap it via pattern-matching.
To Reproduce
Expected behavior
The wrapped value should be extracted as it is.
My environment
Proposed solution
We should stop branching depending on whether the wrapped value is an array. Instead,
#deconstruct
should be simply:However, the above would be a breaking change. Now we have:
The above would change:
IMO, we should nonetheless change it, as the most common use-case for results is extracting the wrapped value after some operations have been performed.
I'm happy to submit a PR fixing the issue. If we consider it as a bug fix, it should go into the next minor or patch release. However, if we consider it as a new feature breaking code, we should wait until v2.0.
The text was updated successfully, but these errors were encountered: