add Partition #1905#1908
Conversation
|
maybe add more tests |
There was a problem hiding this comment.
I would expect to have a partition function that:
- Unwraps the values inside both
SuccessandFailureobjects
So, something like this:
vals = [Result.from_value(1), Result.from_failure('a')]
x: tuple[list[int], list[str]] = returns.methods.partition(vals) # type is inferred automatically, of course
assert x[0] == [1]
assert x[1] == ['a']the same for IOResult must be supported as:
vals = [IOResult.from_value(1), IOResult.from_failure('a')]
x: tuple[list[IO[int]], list[IO[str]]] = returns.methods.partition(vals) # type is inferred automatically, of course
assert x[0] == [IO(1)]
assert x[1] == [IO('a')]I guess that we can use ResultBased interface for that.
|
additional func witch do partition and unwraping? |
|
not additional, but the only one. there's no problem in writing a |
|
finally some working code |
Co-authored-by: sobolevn <mail@sobolevn.me>
Co-authored-by: sobolevn <mail@sobolevn.me>
|
can't understand why IOResult unwrapped to int instead of IO[int] |
sobolevn
left a comment
There was a problem hiding this comment.
Because we used an incorrect interface 🤦
Sorry!
We need this one: https://github.com/dry-python/returns/blob/master/returns/interfaces/specific/result.py#L71
used that, seems like working, got from unwrap_or_failure func |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1908 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 80 81 +1
Lines 2485 2540 +55
Branches 437 447 +10
=========================================
+ Hits 2485 2540 +55 ☔ View full report in Codecov by Sentry. |
Co-authored-by: sobolevn <mail@sobolevn.me>
Co-authored-by: sobolevn <mail@sobolevn.me>
Co-authored-by: sobolevn <mail@sobolevn.me>
I have added partition func to result module
Checklist
CHANGELOG.mdRelated issues
🙏 Please, if you or your company finds
dry-pythonvaluable, help us sustain the project by sponsoring it transparently on https://github.com/sponsors/dry-python. As a thank you, your profile/company logo will be added to our main README which receives hundreds of unique visitors per day.