feat(types): add Pairs
type
This commit is contained in:
parent
8bd63075f4
commit
658d8a7fd6
5
maps.go
5
maps.go
@ -6,8 +6,11 @@ type Pair[K comparable, V any] struct {
|
||||
Value V
|
||||
}
|
||||
|
||||
// Pairs represents collection of key-value pairs
|
||||
type Pairs[K comparable, V any] []Pair[K, V]
|
||||
|
||||
// MapPairs returns list of map's key-value pairs
|
||||
func MapPairs[K comparable, V any](src map[K]V) []Pair[K, V] {
|
||||
func MapPairs[K comparable, V any](src map[K]V) Pairs[K, V] {
|
||||
dst := make([]Pair[K, V], len(src))
|
||||
idx := 0
|
||||
for k, v := range src {
|
||||
|
@ -13,11 +13,11 @@ func TestMapPairs(t *testing.T) {
|
||||
}{
|
||||
"nil map": {
|
||||
src: nil,
|
||||
dst: []Pair[string, int]{},
|
||||
dst: Pairs[string, int]{},
|
||||
},
|
||||
"empty map": {
|
||||
src: map[string]int{},
|
||||
dst: []Pair[string, int]{},
|
||||
dst: Pairs[string, int]{},
|
||||
},
|
||||
"filled map": {
|
||||
src: map[string]int{
|
||||
@ -25,7 +25,7 @@ func TestMapPairs(t *testing.T) {
|
||||
"bar": 2,
|
||||
"baz": 3,
|
||||
},
|
||||
dst: []Pair[string, int]{
|
||||
dst: Pairs[string, int]{
|
||||
{
|
||||
Key: "foo",
|
||||
Value: 1,
|
||||
|
Loading…
Reference in New Issue
Block a user