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

Proposal: considering a new type of Group: a key mapper to a bunch of values, for extend map structure #455

Open
AuZhoomLee opened this issue May 18, 2024 · 0 comments

Comments

@AuZhoomLee
Copy link

Usually, we use one to one mapper: a key to a value of map, but we also like to series a dozen of values in a specific way sometimes, the result is a bunch of values mappers to the same key, that will like be:

// key is a specific regx
kv := map[string]string{"key1-1": "a", "key1-2": "b",  "key2-1": "c", "key2-2": "d"}

or

// inner is a slice
kv := map[string][]string{
	"key1": {"a", "b"},
	"key2": {"c", "d"},
}
// or inner is a map
kv := map[string]map[string]struct{}{
	"key1": {
		"a": struct{}{},
		"b": struct{}{},
	},
	"key2": {
		"c": struct{}{},
		"d": struct{}{},
	},
}

url.Values is so like this and supply some helpful method like Add \ Del \ Get \ Has \ Set
I also used to find a leaf one from the top root a lot in some collection services, who keeps key indexing data.

So, can we considering a new extend type or some method to operate situation like this?
Here's my thought:

type Group[K comparable, V any] map[K][]V

type OrderedGroup[K comparable, S ~[]E, E cmp.Ordered] map[K]S

type UniqGroup[K ,V comparable] map[K]map[V]struct{}

I will supply example implementation later.

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

No branches or pull requests

1 participant