Skip to content

Commit

Permalink
Allow initial elements as variadic into NewOrderedMap
Browse files Browse the repository at this point in the history
  • Loading branch information
pd93 committed Sep 13, 2024
1 parent 9767ae7 commit aed8ebe
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions v2/orderedmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ type OrderedMap[K comparable, V any] struct {
ll list[K, V]
}

func NewOrderedMap[K comparable, V any]() *OrderedMap[K, V] {
return &OrderedMap[K, V]{
kv: make(map[K]*Element[K, V]),
func NewOrderedMap[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
}

// Get returns the value for a key. If the key does not exist, the second return
Expand Down

0 comments on commit aed8ebe

Please sign in to comment.