Skip to content

Commit

Permalink
Use 'shorthand' in docs consistently
Browse files Browse the repository at this point in the history
  • Loading branch information
flyingmutant committed Jan 8, 2023
1 parent 68a5376 commit 24f65e3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 19 deletions.
11 changes: 4 additions & 7 deletions collections.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func ID[V any](v V) V {
return v
}

// SliceOf creates a []E generator. SliceOf(elem) is equivalent to SliceOfN(elem, -1, -1).
// SliceOf is a shorthand for [SliceOfN](elem, -1, -1).
func SliceOf[E any](elem *Generator[E]) *Generator[[]E] {
return SliceOfN(elem, -1, -1)
}
Expand All @@ -31,9 +31,7 @@ func SliceOfN[E any](elem *Generator[E], minLen int, maxLen int) *Generator[[]E]
})
}

// SliceOfDistinct creates a []E generator. Elements of each generated slice are distinct according to keyFn.
// [ID] helper can be used as keyFn to generate slices of distinct comparable elements.
// SliceOfDistinct(elem, keyFn) is equivalent to SliceOfNDistinct(elem, -1, -1, keyFn).
// SliceOfDistinct is a shorthand for [SliceOfNDistinct](elem, -1, -1, keyFn).
func SliceOfDistinct[E any, K comparable](elem *Generator[E], keyFn func(E) K) *Generator[[]E] {
return SliceOfNDistinct(elem, -1, -1, keyFn)
}
Expand Down Expand Up @@ -103,7 +101,7 @@ 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).
// MapOf is a shorthand for [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)
}
Expand All @@ -122,8 +120,7 @@ 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).
// MapOfValues is a shorthand for [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)
}
Expand Down
2 changes: 1 addition & 1 deletion combinators.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (g *mappedGen[U, V]) value(t *T) V {
}

// Just creates a generator which always produces the given value.
// Just(val) is equivalent to SampledFrom([]V{val}).
// Just(val) is a shorthand for [SampledFrom]([]V{val}).
func Just[V any](val V) *Generator[V] {
return SampledFrom([]V{val})
}
Expand Down
15 changes: 4 additions & 11 deletions strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ type compiledRegexp struct {
re *regexp.Regexp
}

// Rune creates a rune generator.
// Rune creates a rune generator. Rune is equivalent to [RuneFrom] with default set of runes and tables.
func Rune() *Generator[rune] {
return runesFrom(true, defaultRunes, defaultTables...)
}
Expand Down Expand Up @@ -139,24 +139,17 @@ func (g *runeGen) value(t *T) rune {
return runes[genIndex(t.s, len(runes), true)]
}

// String creates a UTF-8 string generator. String() is equivalent to StringOf(Rune()).
// String is a shorthand for [StringOf]([Rune]()).
func String() *Generator[string] {
return StringOf(anyRuneGen)
}

// StringN creates a UTF-8 string generator.
// If minRunes >= 0, generated strings have minimum minRunes runes.
// If maxRunes >= 0, generated strings have maximum maxRunes runes.
// If maxLen >= 0, generates strings have maximum length of maxLen.
// StringN panics if maxRunes >= 0 and minRunes > maxRunes.
// StringN panics if maxLen >= 0 and maxLen < maxRunes.
// StringN(minRunes, maxRunes, maxLen) is equivalent to StringOfN(Rune(), minRunes, maxRunes, maxLen).
// StringN is a shorthand for [StringOfN]([Rune](), minRunes, maxRunes, maxLen).
func StringN(minRunes int, maxRunes int, maxLen int) *Generator[string] {
return StringOfN(anyRuneGen, minRunes, maxRunes, maxLen)
}

// StringOf creates a UTF-8 string generator.
// StringOf(elem) is equivalent to StringOfN(elem, -1, -1, -1).
// StringOf is a shorthand for [StringOfN](elem, -1, -1, -1).
func StringOf(elem *Generator[rune]) *Generator[string] {
return StringOfN(elem, -1, -1, -1)
}
Expand Down

0 comments on commit 24f65e3

Please sign in to comment.