-
Notifications
You must be signed in to change notification settings - Fork 315
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
Add Itertools::filter_{,map_}results #377
Conversation
I'm using |
Is there a blocker for this? Trying to gauge acceptance of this PR, as I would like this. |
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.
Hi! As we see from #377 (comment), this is apparently a convenience feature that some people like. So thumbs up from my side.
I was thinking about the following: If I understand this correctly, filter_results
is basically a convenience for a special case of filter
, and I was thinking if it is possible to implement FilterResults
in terms of Filter
, thereby gaining all the knowledge/optimizations already put into Filter
. Or would we lose anything by doing that?
src/adaptors/mod.rs
Outdated
} | ||
|
||
fn size_hint(&self) -> (usize, Option<usize>) { | ||
self.iter.size_hint() |
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.
I am not sure if this is correct. If self.iter
iterates over e.g. a Vec
, I assume that self.iter.size_hint
returns vec.len(), Some(vec.len())
, but due to filtering, our result should be 0, Some(vec.len())
.
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.
You assessment is correct. If this implementation will be used I will fix that.
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.
Can you fix this?
Sounds good, should be less complex than the manual filter implementation.
results in
Manually implementing the |
Ah, thanks for trying - I always fall into this trap. I think if you actually wanted to use this, you would have to specify Regarding manually implementing the So, if we would like to have the feature, we should possibly go with your suggestion. Still, we could leverage Alternatively:
|
I will take a look at
Indeed, where
I think the semantics are closely related to the other existing
Well, what do you know - that already basically exists as |
No worries! I have a big paper deadline in the next two week, so I won't be able to closely review code, anyways. |
Also, what about this? |
I think we do not want to require Rust 1.33 because of this. Thus, I would use a manual `match` for now, and possibly annotate that we use `transpose` once we bump the minimum Rust version.
Am Montag, 17. Februar 2020, 08:38:51 MEZ hat gin-ahirsch <notifications@github.com> Folgendes geschrieben:
I'm using {Option,Result}::transpose(), which is unavailable in 1.24 since it has been stabilized in 1.33. Should I just do it manually (using match)?
Also, what about this?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
Agreed! |
I looked at |
75f5df2
to
b381e2b
Compare
I'm using |
b381e2b
to
75f5df2
Compare
I wonder if |
The current names are in line with the currently available |
Let's do this. |
Also remove calls to Result::transpose() to stay compatible to Rust 1.24.
4bd644c
to
3890a93
Compare
Thanks! bors r+ |
Build succeeded: |
I found myself wanting
filter_map_results()
and just implementedfilter_results()
in the same stretch. I hope you find it useful!I wasn't sure if #236 applies to these new iterators; I just implemented them.