Skip to content

Support sort(keys(::Dict)) and sort(values(::Dict))#56978

Merged
LilithHafner merged 6 commits intomasterfrom
lh/sort-key-value
Mar 19, 2025
Merged

Support sort(keys(::Dict)) and sort(values(::Dict))#56978
LilithHafner merged 6 commits intomasterfrom
lh/sort-key-value

Conversation

@LilithHafner
Copy link
Copy Markdown
Member

Part of the sorting iterables saga:
#38328
#46104
#51977
#52010
#54494

@LilithHafner LilithHafner added iteration Involves iteration or the iteration protocol sorting Put things in order labels Jan 6, 2025
@nsajko nsajko added the collections Data structures holding multiple items, e.g. sets label Jan 7, 2025
Comment thread base/sort.jl Outdated
Co-authored-by: Neven Sajko <[email protected]>
@LilithHafner LilithHafner merged commit be3221f into master Mar 19, 2025
5 of 7 checks passed
@LilithHafner LilithHafner deleted the lh/sort-key-value branch March 19, 2025 14:54
LilithHafner added a commit that referenced this pull request Mar 26, 2025
In cases where a function is documented as 
```
    function(arg::ArgT, arg2::Arg2T) -> RetT

...
```
I either switched ` -> ` to `::` or switched `RetT` to `ret_name::RetT`.

From the recommendation and justification from @nsajko here:
#56978 (comment) and
applied throughout the repo.

As documented here #57583

Also includes some minor changes to touched lines (e.g. removing annotations that are just clutter)
serenity4 pushed a commit to serenity4/julia that referenced this pull request May 1, 2025
In cases where a function is documented as 
```
    function(arg::ArgT, arg2::Arg2T) -> RetT

...
```
I either switched ` -> ` to `::` or switched `RetT` to `ret_name::RetT`.

From the recommendation and justification from @nsajko here:
JuliaLang#56978 (comment) and
applied throughout the repo.

As documented here JuliaLang#57583

Also includes some minor changes to touched lines (e.g. removing annotations that are just clutter)
@KristofferC
Copy link
Copy Markdown
Member

KristofferC commented Mar 18, 2026

Should this be reverted (for the same reason as the other PR)? I don't see any discussion about this, just a PR and then merge by the author, and #52010 also applies here? It's a weird special case in my opinion.

@mbauman
Copy link
Copy Markdown
Member

mbauman commented Mar 18, 2026

Well, I guess the question is what the behaviors of the hypothetical future alternative type would be. sort(values(::Dict)) could be a SortedVector and sort(keys(::Dict)) could be an OrderedSet or SortedSet. All of these would be slightly more similar to a Vector than an OrderedDict is, but all would indeed have subtly different downstream behaviors on push! and probably a few other methods.

The only way we'd care to reserve such future behaviors is if we'd want to implement any of these types in the future. I don't see such value in the values case. The keys are slightly different, but it makes sense to treat them the same.

@adienes
Copy link
Copy Markdown
Member

adienes commented Mar 18, 2026

I still like #51977 (comment) . not sure if that was fully considered & rejected yet or if it's still on the table

@mbauman
Copy link
Copy Markdown
Member

mbauman commented Mar 18, 2026

#51977 (comment)

what about documenting that sort(::SomeType) must return something iterable with matching eltype, but the exact container is implementation dependent? then Vector{Pair} --> OrderedDict is not breaking semver

I think that might be defensible for a Vector{T} -> OrderedSet{T}, and is definitely defensible for some Vector{T} -> AbstractVector{T}, but I really don't think it's defensible for Vector{Pair{K,V}} -> Dict{K,V} because their behaviors simply diverge too much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

collections Data structures holding multiple items, e.g. sets iteration Involves iteration or the iteration protocol sorting Put things in order

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants