-
Notifications
You must be signed in to change notification settings - Fork 502
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
all: Add some generics and incorporate them into the codebase. #4532
Conversation
support/generics/math.go
Outdated
@@ -0,0 +1,21 @@ | |||
package generics |
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.
generics
is a reasonably generic name. Given that this package contains functions that work with ordered types, how about we named it ordered
?
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 idea was to expand it over time to include other helpers (as you can tell from my ambitious branch naming). Min/Max are the most obvious offenders, but now that I've added and incorporated a Set[T any]
container, would you reconsider the rename? 😉
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.
I also plan to add both
func mapKeys[T any, U any](m map[T]U) []T // and
func mapValues[T any, U any](m map[T]U) []U
once this gets merged into the lighthorizon
branch.
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.
I'd put the map functions into a collections/map
package, and the Set
type into a collections/set
package. i.e.
ordered
collections/set
collections/map
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.
This is a small detail and I defer to you. It's great we can do these things now 🎉.
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.
I guess my goal was to keep everything in its own subfolder (with no explicit reason besides it being a 1.18+ feature and the general satisfaction of keeping a PR in a single folder), but I do like these names! Done in 4d58a36.
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.
👏🏻
support/generics/math.go
Outdated
@@ -0,0 +1,21 @@ | |||
package generics |
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.
This is a small detail and I defer to you. It's great we can do these things now 🎉.
2a75d53
to
724dd7f
Compare
support/generics
library and incorporate it into the codebase.
PR Checklist
PR Structure
otherwise).
services/friendbot
, orall
ordoc
if the changes are broad or impact manypackages.
Thoroughness
.md
files, etc... affected by this change). Take a look in the
docs
folder for a given service,like this one.
Release planning
needed with deprecations, added features, breaking changes, and DB schema changes.
semver, or if it's mainly a patch change. The PR is targeted at the next
release branch if it's not a patch change.
What
Adds and incorporates a generic
Min
/Max
rather than customs ones per-type and per-package.Why
blessed generics
Known limitations
There might be other places we're doing this inline that are much harder to find, e.g.
one-offs that didn't warrant a dedicated
min
for that package.