-
-
Notifications
You must be signed in to change notification settings - Fork 143
Issue 1114 #1131
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
Issue 1114 #1131
Conversation
sobolevn
commented
Nov 16, 2021
We also need to make an interface type for filter. This way we will be able to use with HKT.
See interfaces/ folder.
CucumisSativus
commented
Nov 18, 2021
@sobolevn I think i managed to add them, but lets say i'm not 100% sure about those. Looking forward for some feedback :)
@sobolevn
sobolevn
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot! Just one question 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Future note: we can also make an overload for TypeGuard case.
See python/typeshed#6140
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you elaborate a bit what can we do with type guard here? We are not filtering for example a list with different types. Filter executed on _FilterableType always returns _FilterableType. Did I miss something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nevermind, this was a self note 🙂
This is even not supported by mypy yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like mypy supports TypeGuard now 🎉 :
returns/maybe.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to create a common filter_ function for all possible types? Result, IOResult, ...?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
filter is special in the sense that it 'empties' the container, which is possible in Maybe, but not in Result (i.e. what would the failure value of Success(4).filter(lambda x: False) be?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I see! Than, it looks like we can use MaybeLikeN to limit the input type of filter_?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sobolevn I used it, please tell me if its something you were looking for. I am not entirely sure if I did it right :)
CucumisSativus
commented
Nov 23, 2021
@sobolevn when i'm running poetry run pytest typesafety -p no:cov -o addopts="" --mypy-ini-file=setup.cfg locally I get 830 passed, 1 warning. Any ideas why does it fail on github?
sobolevn
commented
Nov 23, 2021
I will take a look a bit later this week.
Thanks a lot for the PR!
returns/interfaces/filterable.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: fo->of
returns/interfaces/filterable.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what would you think of naming the example function? Naming the function is_even makes the example clearer in my mind
f4bf1be to
aa3a303
Compare
e216c9c to
60950f6
Compare
CucumisSativus
commented
Dec 11, 2021
@sobolevn i think I found it
Codecov Report
All modified and coverable lines are covered by tests ✅
Project coverage is 100.00%. Comparing base (
b782c2e) to head (cca6894).
Report is 624 commits behind head on master.
Additional details and impacted files
@@ Coverage Diff @@ ## master #1131 +/- ## ========================================= Coverage 100.00% 100.00% ========================================= Files 79 81 +2 Lines 2415 2450 +35 Branches 208 210 +2 ========================================= + Hits 2415 2450 +35
☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.
I have made things!
Checklist
CHANGELOG.mdRelated issues
Refs #1114
A simple implementation of filter for maybe. I am happy to implement something similar for Result, but I'm not entirely sure about the preferred approach.
In Scala it looks more or less like this
Not sure if something like this is ok for Python as well.
My second idea was to have a signature like
so user can specify exactly what happens in case of not matching predicate
🙏 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.