From 658d8a7fd6a032c65531b2a708da5c87417a7caf Mon Sep 17 00:00:00 2001 From: Piotr Icikowski Date: Tue, 21 May 2024 22:39:52 +0200 Subject: [PATCH] feat(types): add `Pairs` type --- maps.go | 5 ++++- maps_test.go | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/maps.go b/maps.go index 9e0b5ef..f4533c0 100644 --- a/maps.go +++ b/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 { diff --git a/maps_test.go b/maps_test.go index b517ff8..20bd2da 100644 --- a/maps_test.go +++ b/maps_test.go @@ -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,