Skip to content

Commit 034bafe

Browse files
committed
utils: create 'KeyValue' type
Create a 'KeyValue' type, identical to 'testhelpers.Pair' other than its field names ('Key'/'Value' vs. 'First'/'Second'). See the comment in the newly-created 'utils/types.go' for more information about why a new type was created, rather than moving 'testhelpers.Pair' into 'utils'. This 'KeyValue' type will be used in future commits as a way of passing arbitrary configuration options to functions. Signed-off-by: Victoria Dye <[email protected]>
1 parent 3bba87c commit 034bafe

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

internal/utils/types.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package utils
2+
3+
// KeyValue is very similar to testhelpers.Pair. Consider unifying on a single
4+
// 'utils.Pair' if https://github.com/golang/go/issues/52654 is ever
5+
// implemented. With that, we can alias 'utils.NewPair' in 'testhelpers' with:
6+
//
7+
// func NewPair = utils.NewPair
8+
//
9+
// and avoid the need to either prefix all 'NewPair' calls with 'utils.' (since
10+
// we don't want to dot-import 'utils' either).
11+
12+
type KeyValue[T any, R any] struct {
13+
Key T
14+
Value R
15+
}
16+
17+
func NewKeyValue[T any, R any](key T, value R) KeyValue[T, R] {
18+
return KeyValue[T, R]{
19+
Key: key,
20+
Value: value,
21+
}
22+
}

0 commit comments

Comments
 (0)