Skip to content

Sort undefined according to the comparison function #195

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

Merged
merged 1 commit into from
Dec 22, 2020

Conversation

kl0tl
Copy link
Member

@kl0tl kl0tl commented Dec 21, 2020

This pull request implements Data.Array.sortBy and Data.Array.ST.sortBy with the merge sort proposed in #155, so that undefined is sorted according to the comparison function and not to the end of the array (this also applies to Data.Array.NonEmpty.sortBy because it is implemented with Data.Array.sortBy). The only liberty I took with the implementation was to get rid of the uncurried functions since we’re not using any elsewhere in this library.

Do we also want unsafeSort :: forall a. Ord a => Array a -> Array a, unsafeSortBy :: forall a. (a -> a -> Ordering) -> Array a -> Array a and unsafeSortWith :: forall a b. Ord b => (a -> b) -> Array a -> Array a functions, implemented with the native Array.prototype.sort method?

Close #155.

Copy link
Contributor

@hdgarrood hdgarrood left a comment

Choose a reason for hiding this comment

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

Looks good! I wouldn’t bother with unsafeSort, I expect it’s quite rare that there’s a difference that matters and it’ll be a pain for alternate backend maintainers.

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.

sort/sortBy Does Not Use The Correct Ordering & Violates Parametricity
3 participants