Skip to content

sorting for NonEmptyList #97

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
May 28, 2017
Merged

Conversation

matthewleon
Copy link
Contributor

Adds the two sorting functions to NonEmptyList.

@paf31
Copy link
Contributor

paf31 commented May 28, 2017

@garyb I think we can make this a minor version bump, yes?

sort xs = sortBy compare xs

sortBy :: forall a. (a -> a -> Ordering) -> NonEmptyList a -> NonEmptyList a
sortBy cmp xs = unsafeFromList $ L.sortBy cmp (toList xs)
Copy link
Contributor

Choose a reason for hiding this comment

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

Another option here is to sort the tail and insert the head into the sorted result, a la insertion sort. That would require us to change the type of insert though, or to provide an alternative version.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@paf31 are you suggesting we should go down that route? I understand that unsafeFromList is, in many cases, a last resort, but here it seems to be both safe and more efficient than the alternative.

Copy link
Member

Choose a reason for hiding this comment

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

I'd vote for the unsafeFromList version here too, personally. :)

@paf31
Copy link
Contributor

paf31 commented May 28, 2017

@matthewleon Sorry for the delay, could you please rebase?

@garyb
Copy link
Member

garyb commented May 28, 2017

I think we can make this a minor version bump, yes?

Agreed 👍

@matthewleon
Copy link
Contributor Author

Sorry for the delay, could you please rebase?

done

@paf31 paf31 merged commit ca01c22 into purescript:master May 28, 2017
@paf31
Copy link
Contributor

paf31 commented May 28, 2017

Thanks!

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.

3 participants