Skip to content

Rewrite the PG uniq function to return the array in a consistent order #1298

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
Aug 5, 2025

Conversation

dlglin
Copy link
Member

@dlglin dlglin commented Jul 24, 2025

This is to address #1275. Find a MWE to test there.

With this update (supplied by @drgrice1 ) uniq now always returns the array in the same order.

Copy link
Member

@drgrice1 drgrice1 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. Of course it is the code I gave you, so this probably doesn't say much!

Copy link
Member

@pstaabp pstaabp 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.

Does this work because grep keeps the same order as the input? Whereas using a hash doesn't preserve order?

@duffee
Copy link
Contributor

duffee commented Aug 5, 2025

Your other option is to use the List::Util's uniq function. The module has been in core since 5.7-5.10 which is old enough to expect it in all(?) distributions. That decision hinges on your feeling about adding dependencies. Like the grep solution above, it also returns results in the same order and may have been optimized for speed. Just a thought.

@drgrice1
Copy link
Member

drgrice1 commented Aug 5, 2025

Does this work because grep keeps the same order as the input? Whereas using a hash doesn't preserve order?

Yes. That is basically it.

@Alex-Jordan Alex-Jordan merged commit df2eb9d into openwebwork:develop Aug 5, 2025
3 checks passed
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.

5 participants