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

add Vector::insert_ord_by[_key] methods #23

Merged
merged 1 commit into from
Aug 15, 2021

Conversation

vlmutolo
Copy link
Contributor

Users frequently want to use a custom ordering for their Vector types. One way to accomplish this is to implement the Ord trait (along with PartialOrd and usually PartialEq/Eq) using the desired custom logic for comparisons.

However, this can lead to a lot of boilerplate code for what is often a small, one-off use case. This has to to the Standard Library, and libraries like imbl that offer similar APIs, creating methods such as sort_by, sort_by_key, etc. that allow a user to pass a comparator function that the library will use to sort or insert into the list.

This PR implements the insert_ord_by and insert_order_by_key methods, providing a way to use a custom comparator function to insert into a sorted list without needing to define the usual Rust comparison traits.

@vlmutolo vlmutolo force-pushed the vector-insert-ord-by branch from a7ab4df to 5bbdce5 Compare August 14, 2021 22:02
@vlmutolo
Copy link
Contributor Author

This PR is a resubmission of the PR made on the original im crate.

Users frequently want to use a custom ordering for their Vector types.
One way to accomplish this is to implement the Ord trait (along with
PartialOrd and usually PartialEq/Eq) using the desired custom logic for
comparisons.

However, this can lead to a lot of boilerplate code for what is often a
small, one-off use case. This has to to the Standard Library, and
libraries like imbl that offer similar APIs, creating methods such as
sort_by, sort_by_key, etc. that allow a user to pass a comparator
function that the library will use to sort or insert into the list.

This PR implements the insert_ord_by and insert_order_by_key methods,
providing a way to use a custom comparator function to insert into a
sorted list without needing to define the usual Rust comparison traits.
@vlmutolo vlmutolo force-pushed the vector-insert-ord-by branch from 5bbdce5 to 318670d Compare August 14, 2021 22:46
Copy link
Owner

@jneem jneem left a comment

Choose a reason for hiding this comment

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

Thanks! And for the nice docs, too :)

@jneem jneem merged commit 3fd258c into jneem:main Aug 15, 2021
@vlmutolo
Copy link
Contributor Author

Thanks for the quick merge! That was an impressive turnaround time. checks watch I think it's been two hours.

@vlmutolo vlmutolo deleted the vector-insert-ord-by branch August 15, 2021 00:56
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.

2 participants