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

Improve concision #23

Merged
merged 3 commits into from
May 15, 2022
Merged

Conversation

clint-white
Copy link
Contributor

Here are some suggestions for making the code a little more concise in a few places.

  • Use match ergonomics and Ordering::then_with() in Counter::most_common_tiebreaker().
  • Remove unnecessary explicit use of .into_iterator() in for loops
  • Replace a redundant closure with the method it was calling

Use match ergonomics to simplify the pattern matching.  When matching a
reference value with a non-reference pattern, the default binding mode
is automatically set to `ref`.  In this case, by removing the `&` on the
tuples and the `ref` keywords on their fields, the variables
`{a,b}_{item,count}` are bound as references.

Replace the `match` expression with `Ordering::then_with()`, which does
the same thing more succinctly.
We can directly loop over containers of type `I: IntoIter` without
having to call `IntoIter::into_iter()` explicitly; that is part of the
syntactic sugar of `for`-loops.
@coriolinus coriolinus merged commit 623fb6c into coriolinus:master May 15, 2022
@clint-white clint-white deleted the improve-concision branch May 15, 2022 18:54
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.

None yet

2 participants