Skip to content
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

Merged
merged 7 commits into from
Aug 11, 2022

Conversation

Shaptic
Copy link
Contributor

@Shaptic Shaptic commented Aug 10, 2022

PR Checklist

PR Structure

  • This PR has reasonably narrow scope (if not, break it down into smaller PRs).
  • This PR avoids mixing refactoring changes with feature changes (split into two PRs
    otherwise).
  • This PR's title starts with name of package that is most changed in the PR, ex.
    services/friendbot, or all or doc if the changes are broad or impact many
    packages.

Thoroughness

  • This PR adds tests for the most critical parts of the new functionality or fixes.
  • I've updated any docs (developer docs, .md
    files, etc... affected by this change). Take a look in the docs folder for a given service,
    like this one.

Release planning

  • I've updated the relevant CHANGELOG (here for Horizon) if
    needed with deprecations, added features, breaking changes, and DB schema changes.
  • I've decided if this PR requires a new major/minor version according to
    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.

if a < b {
    a = b
}

one-offs that didn't warrant a dedicated min for that package.

@Shaptic Shaptic requested review from leighmcculloch and a team August 10, 2022 22:32
@@ -0,0 +1,21 @@
package generics
Copy link
Member

@leighmcculloch leighmcculloch Aug 10, 2022

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?

Copy link
Contributor Author

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? 😉

Copy link
Contributor Author

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.

Copy link
Member

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

Copy link
Member

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 🎉.

Copy link
Contributor Author

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.

Copy link
Member

@leighmcculloch leighmcculloch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏🏻

@@ -0,0 +1,21 @@
package generics
Copy link
Member

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 🎉.

@Shaptic Shaptic enabled auto-merge (squash) August 11, 2022 07:54
@Shaptic Shaptic changed the title all: Add a support/generics library and incorporate it into the codebase. all: Add some generics and incorporate them into the codebase. Aug 11, 2022
@Shaptic Shaptic merged commit 8448622 into stellar:master Aug 11, 2022
@Shaptic Shaptic deleted the templatedUtils branch August 11, 2022 16:00
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.

2 participants