You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think it's better in general for the standard docs to contain examples that are easy to understand, but are also realistic usages of functions and features. An example of this is in slice::binary_search that shows how to insert an item to a sorted vector while maintaining sort order.
So I think the docs of Iterator::reduce could be improved with a more real usage example (to replace the current find_max example). And I think such docs should also say that reduce is useful when your binary operation doesn't have an identity element (or when you don't want to use it for some reason, like efficiency, etc).
The text was updated successfully, but these errors were encountered:
Given the close similarity to Iterator::fold it should also show an example that demonstrates when they are equivalent, so that people who understand one can understand the other (and hopefully understand the situations in which to use each).
…ple, r=thomcc,vacuus
Improve example of Iterator::reduce
Fixes #81819.
I took your example `@bstrie` from rust-lang/rust#81819 and applied it here.
r? `@thomcc`
I think it's better in general for the standard docs to contain examples that are easy to understand, but are also realistic usages of functions and features. An example of this is in slice::binary_search that shows how to insert an item to a sorted vector while maintaining sort order.
So I think the docs of Iterator::reduce could be improved with a more real usage example (to replace the current find_max example). And I think such docs should also say that reduce is useful when your binary operation doesn't have an identity element (or when you don't want to use it for some reason, like efficiency, etc).
The text was updated successfully, but these errors were encountered: