History

Document map generators

Gregory Petrosyan committed 3 years ago

Commit 29bc9271 parent 95a77e41 file · +9 −0Browse files

Unified · Split

collections.go+9−0
@@ -103,10 +103,14 @@ func (g *sliceGen[E, K]) value(t *T) []E { · 102 unmodified lines
103103 return sl
104104 }
105105
106+// MapOf creates a map[K]V generator. MapOf(key, val) is equivalent to MapOfN(key, val, -1, -1).
106107 func MapOf[K comparable, V any](key *Generator[K], val *Generator[V]) *Generator[map[K]V] {
107108 return MapOfN(key, val, -1, -1)
108109 }
109110
111+// MapOfN creates a map[K]V generator. If minLen >= 0, generated maps have minimum length of minLen.
112+// If maxLen >= 0, generated maps have maximum length of maxLen. MapOfN panics if maxLen >= 0
113+// and minLen > maxLen.
110114 func MapOfN[K comparable, V any](key *Generator[K], val *Generator[V], minLen int, maxLen int) *Generator[map[K]V] {
111115 assertValidRange(minLen, maxLen)
112116
@@ -118,10 +122,15 @@ func MapOfN[K comparable, V any](key *Generator[K], val *Generator[V], minLen in · 5 unmodified lines
118122 })
119123 }
120124
125+// MapOfValues creates a map[K]V generator, where keys are generated by applying keyFn to values.
126+// MapOfValues(val, keyFn) is equivalent to MapOfNValues(val, -1, -1, keyFn).
121127 func MapOfValues[K comparable, V any](val *Generator[V], keyFn func(V) K) *Generator[map[K]V] {
122128 return MapOfNValues(val, -1, -1, keyFn)
123129 }
124130
131+// MapOfNValues creates a map[K]V generator, where keys are generated by applying keyFn to values.
132+// If minLen >= 0, generated maps have minimum length of minLen. If maxLen >= 0, generated maps
133+// have maximum length of maxLen. MapOfNValues panics if maxLen >= 0 and minLen > maxLen.
125134 func MapOfNValues[K comparable, V any](val *Generator[V], minLen int, maxLen int, keyFn func(V) K) *Generator[map[K]V] {
126135 assertValidRange(minLen, maxLen)
127136

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t