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
103 return sl103 return sl
104}104}
105 105
106// MapOf creates a map[K]V generator. MapOf(key, val) is equivalent to MapOfN(key, val, -1, -1).
106func MapOf[K comparable, V any](key *Generator[K], val *Generator[V]) *Generator[map[K]V] {107func MapOf[K comparable, V any](key *Generator[K], val *Generator[V]) *Generator[map[K]V] {
107 return MapOfN(key, val, -1, -1)108 return MapOfN(key, val, -1, -1)
108}109}
109 110
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.
110func MapOfN[K comparable, V any](key *Generator[K], val *Generator[V], minLen int, maxLen int) *Generator[map[K]V] {114func MapOfN[K comparable, V any](key *Generator[K], val *Generator[V], minLen int, maxLen int) *Generator[map[K]V] {
111 assertValidRange(minLen, maxLen)115 assertValidRange(minLen, maxLen)
112 116
@@ -118,10 +122,15 @@ func MapOfN[K comparable, V any](key *Generator[K], val *Generator[V], minLen in · 5 unmodified lines
118 })122 })
119}123}
120 124
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).
121func MapOfValues[K comparable, V any](val *Generator[V], keyFn func(V) K) *Generator[map[K]V] {127func MapOfValues[K comparable, V any](val *Generator[V], keyFn func(V) K) *Generator[map[K]V] {
122 return MapOfNValues(val, -1, -1, keyFn)128 return MapOfNValues(val, -1, -1, keyFn)
123}129}
124 130
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.
125func MapOfNValues[K comparable, V any](val *Generator[V], minLen int, maxLen int, keyFn func(V) K) *Generator[map[K]V] {134func MapOfNValues[K comparable, V any](val *Generator[V], minLen int, maxLen int, keyFn func(V) K) *Generator[map[K]V] {
126 assertValidRange(minLen, maxLen)135 assertValidRange(minLen, maxLen)
127 136

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