Skip to content
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

Feature process_results as an Itertools method #587

Closed

Conversation

danielhenrymantilla
Copy link
Contributor

Fixes #557

Copy link
Member

@phimuemue phimuemue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi there, thanks for this, it's appreciated.

As of now, the majority of free function is documented as follows:

  • Summary line
  • IntoIterator enabled version of method.

To enforce some consistency, could you please go with that pattern?

Comment on lines +870 to +872
/// `processor` is a closure that receives an adapted version of the iterator
/// as the only argument — the adapted iterator produces elements of type `Ok`,
/// as long as the original iterator produces `Ok` values.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This documentation differs slightly from what we have at https://docs.rs/itertools/0.10.3/itertools/fn.process_results.html, and I think, the choice of Ok is misleading, as it hints at a Result - https://docs.rs/itertools/0.10.3/itertools/fn.process_results.html goes with T, I suggest copying that to have it in line.

/// return the error iself.
///
/// Otherwise, the return value from the closure is returned wrapped
/// inside `Ok`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is misleading, as this Ok refers to Result::Ok (and not the local type Ok). Or am I missing something?

/// assert!(second_max.is_err());
/// ```
///
/// This is the iterator adaptor version of [`itertools::process_results()`].
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice.

/// [`itertools::process_results`]: `crate::process_results`
fn process_results<F, Ok, Err, R>(self, processor: F) -> Result<R, Err>
where Self: Iterator<Item = Result<Ok, Err>> + Sized,
F: for<'r> FnOnce(ProcessResults<'r, Self, Err>) -> R,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the higher kinded lifetime (i.e. for<'r>) necessary?

where Self: Iterator<Item = Result<Ok, Err>> + Sized,
F: for<'r> FnOnce(ProcessResults<'r, Self, Err>) -> R,
// Added to directly highlight the relevant impl in the documentation
for<'r> ProcessResults<'r, Self, Err>: Iterator<Item = Ok>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this? If it's only for documentation, I'd prefer to remove it and not bother the type checker with it. If we really want it in the documentation, we can still state it explicitly.

bors bot added a commit that referenced this pull request Mar 11, 2022
591: Canonicalize free functions r=jswrenn a=phimuemue

As made visible by #587, I think we should have (somewhat) uniform documentation of free functions.

On top of that, I think `fn equal` should actually use `Iterator::eq` (available since Rust 1.5), instead of only referring to it in the documentation.

Maybe someone finds time to have a look at this, as I'd like to avoid silly mistakes before merging.

Co-authored-by: philipp <descpl@yahoo.de>
@sjackman
Copy link

sjackman commented Sep 8, 2022

@danielhenrymantilla Thanks for this work, Daniel. Gentle nudge. I'd love to see this PR merged.

bors bot added a commit that referenced this pull request Mar 22, 2023
680: Feature `process_results` as an `Itertools` method r=phimuemue a=Philippe-Cholet

Fixes #557 
I hope it's okay for me to propose an alternative pull request to #587 because it seems stuck for some time: misleading generics names Ok/Err, unnecessary ? higher kinded lifetime.

I will be around to change things if necessary, the documentation maybe, what should I write?

Co-authored-by: Philippe-Cholet <phcholet@orange.fr>
@phimuemue
Copy link
Member

Thanks for bringing this up.

We took the idea, but went with the somewhat simpler #680

@phimuemue phimuemue closed this Mar 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

process_results on the Itertools trait
3 participants