-
-
Notifications
You must be signed in to change notification settings - Fork 497
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
[CLEANUP] Replace experimental maps
and slices
with stdlib
#2993
[CLEANUP] Replace experimental maps
and slices
with stdlib
#2993
Conversation
The experimental functions are now available in the standard library in Go 1.23 [1]. [1]: https://go.dev/doc/go1.23#new-unique-package Signed-off-by: Eng Zer Jun <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few questions I guess
return slices.SortedFunc(bes, func(a, b V) int { | ||
return cmp.Compare(a.Priority(), b.Priority()) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why can't you use slices.Sorted
directly? I'd expect Priority()
to return a cmp.Ordered
value, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't use slices.Sorted
.
You can see the types permitted by cmp.Ordered
here: https://pkg.go.dev/cmp#Ordered. We are using generics so it is not possible to use slices.Sorted
here.
_, ok := c.vars["core.sshCommand"] | ||
assert.True(t, ok) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not use SortedKeys
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The old code
assert.Contains(t, maps.Keys(c.vars), "core.sshCommand")
was just testing whether the core.sshCommand
key exists in the c.vars
map or not.
Obviously we can do assert.Contains(t, set.SortedKeys(c.vars), "core.sshCommand")
too to test whether core.sshCommand
exists in c.vars
or not. But _, ok := c.vars["core.sshCommand"]
does the job in a much simplier way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
The experimental functions are now available in the standard library in Go 1.23 1.
The only difference is that
maps.Keys
andmaps.Values
in the standard library return an iterator, whilemaps.Keys
andmaps.Values
in thegolang.org/x/exp
package return a slice.Footnotes
https://go.dev/doc/go1.23#new-unique-package ↩