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

Initialising an ordered map with data #43

Open
pd93 opened this issue Sep 9, 2024 · 1 comment · May be fixed by #45
Open

Initialising an ordered map with data #43

pd93 opened this issue Sep 9, 2024 · 1 comment · May be fixed by #45

Comments

@pd93
Copy link

pd93 commented Sep 9, 2024

Hi. I've been looking at using this in go-task instead of our naive implementation. Would you be open to a PR that added the ability to easily create an ordered map containing a set of initial data? since OrderedMap.kv and OrderedMap.ll are not exported, it is not possible to create an inline structure. I've been using .Set() for this instead, but this can be quite cumbersome when writing table-tests or similar.

I was thinking something along the lines of:

func NewOrderedMapWithElements[K comparable, V any](els ...*Element[K, V]) *OrderedMap[K, V] {
	om := &OrderedMap[K, V]{
		kv: make(map[K]*Element[K, V], len(els)),
	}
	for _, el := range els {
		om.Set(el.Key, el.Value)
	}
	return om
}

Or perhaps something using the functional options pattern if you prefer. If you're open to this, I'm happy to open a PR.

@elliotchance
Copy link
Owner

Sure, I'll be happy to access that as a PR.

@pd93 pd93 linked a pull request Sep 13, 2024 that will close this issue
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 a pull request may close this issue.

2 participants