Skip to content

Swap sortKeys bool for keySort function - #315

Open
kevboh wants to merge 3 commits into
jpsim:mainfrom
kevboh:feat-add-sort-key-function
Open

Swap sortKeys bool for keySort function#315
kevboh wants to merge 3 commits into
jpsim:mainfrom
kevboh:feat-add-sort-key-function

Conversation

@kevboh

@kevboh kevboh commented Apr 5, 2021

Copy link
Copy Markdown

(This is a breaking change, but I can make it non-breaking if preferred. It's just a lot more code repetition if non-breaking.)

This changes the sortKeys option to be a more flexible keySort function. The function defaults to nil—do not sort—but can be anything that sorts Nodes. I ran into an issue where I wanted a custom sort on a mapping.

@jpsim

jpsim commented Apr 7, 2021

Copy link
Copy Markdown
Owner

Thanks for the PR! Could you please rebase your commits on top of main? That should fix the failing CMake CI jobs.

@kevboh
kevboh force-pushed the feat-add-sort-key-function branch from 19933d7 to 8c97204 Compare April 11, 2021 11:26
@kevboh

kevboh commented Apr 11, 2021

Copy link
Copy Markdown
Author

@jpsim this has been rebased. Thanks for taking a look!

@kevboh

kevboh commented Apr 17, 2021

Copy link
Copy Markdown
Author

@jpsim let me know if anything else is required here.

@kevboh

kevboh commented Jun 20, 2021

Copy link
Copy Markdown
Author

Hi, is this still mergeable? If so I'd love to merge it!

@lynchsft

Copy link
Copy Markdown
Collaborator

Hello! I'm sorry that the communication failed in 2021. The project is under more active maintenance now.

I'm not a fan of the source-breaking change of turning sortKeys into keySort.

I do however appreciate the ability to custom-sort the keys.

This is what I propose:

Introduce a KeySort enum type with:

  • a .natural case which performs the natural < sort
  • a .custom((Key, Key)->Bool) case for custom sorting.
  • a .none case for non-sorting.

If KeySort conforms to ExpressibleAsBooleanLitteral then true can map to .natural and false can map to .none.

With this arrangement we can gain custom sorting without breaking backward compatibility with uses of the existing sort behavior.

Thoughts?

@kevboh

kevboh commented Feb 26, 2025

Copy link
Copy Markdown
Author

I don't write Swift professionally anymore or use this project, so I defer to you!

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