From 29bc9272b2dfe3dbc819cfe2d2d51584c2b652d4 Mon Sep 17 00:00:00 2001 From: Gregory Petrosyan Date: Sun, 8 Jan 2023 19:21:09 +0300 Subject: [PATCH] Document map generators --- collections.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/collections.go b/collections.go index c006799..319e01a 100644 --- a/collections.go +++ b/collections.go @@ -103,10 +103,14 @@ func (g *sliceGen[E, K]) value(t *T) []E { return sl } +// MapOf creates a map[K]V generator. MapOf(key, val) is equivalent to MapOfN(key, val, -1, -1). func MapOf[K comparable, V any](key *Generator[K], val *Generator[V]) *Generator[map[K]V] { return MapOfN(key, val, -1, -1) } +// MapOfN creates a map[K]V generator. If minLen >= 0, generated maps have minimum length of minLen. +// If maxLen >= 0, generated maps have maximum length of maxLen. MapOfN panics if maxLen >= 0 +// and minLen > maxLen. func MapOfN[K comparable, V any](key *Generator[K], val *Generator[V], minLen int, maxLen int) *Generator[map[K]V] { assertValidRange(minLen, maxLen) @@ -118,10 +122,15 @@ func MapOfN[K comparable, V any](key *Generator[K], val *Generator[V], minLen in }) } +// MapOfValues creates a map[K]V generator, where keys are generated by applying keyFn to values. +// MapOfValues(val, keyFn) is equivalent to MapOfNValues(val, -1, -1, keyFn). func MapOfValues[K comparable, V any](val *Generator[V], keyFn func(V) K) *Generator[map[K]V] { return MapOfNValues(val, -1, -1, keyFn) } +// MapOfNValues creates a map[K]V generator, where keys are generated by applying keyFn to values. +// If minLen >= 0, generated maps have minimum length of minLen. If maxLen >= 0, generated maps +// have maximum length of maxLen. MapOfNValues panics if maxLen >= 0 and minLen > maxLen. func MapOfNValues[K comparable, V any](val *Generator[V], minLen int, maxLen int, keyFn func(V) K) *Generator[map[K]V] { assertValidRange(minLen, maxLen)