✨ Add Make method to Generator
This commit is contained in:
parent
1677a692d1
commit
1008a064d0
2 changed files with 19 additions and 0 deletions
|
|
@ -7,6 +7,12 @@ import "errors"
|
||||||
// for example.
|
// for example.
|
||||||
type Generator func(conf *Config) (string, error)
|
type Generator func(conf *Config) (string, error)
|
||||||
|
|
||||||
|
// Make allows you to generate a new string directly from a generator.
|
||||||
|
func (g Generator) Make(opts ...Option) (string, error) {
|
||||||
|
opts = append(opts, WithGenerator(g))
|
||||||
|
return Make(NewConfig(opts...))
|
||||||
|
}
|
||||||
|
|
||||||
// WithGenerator sets the specified generator
|
// WithGenerator sets the specified generator
|
||||||
func WithGenerator(g Generator) Option {
|
func WithGenerator(g Generator) Option {
|
||||||
return func(c *Config) {
|
return func(c *Config) {
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,19 @@ func ExampleWithGenerator_customGenerator() {
|
||||||
// hello
|
// hello
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ExampleGenerator_Make() {
|
||||||
|
g := nomino.Incremental()
|
||||||
|
st, _ := g.Make()
|
||||||
|
fmt.Println(st)
|
||||||
|
|
||||||
|
st, _ = g.Make(nomino.WithPrefix("foo"))
|
||||||
|
fmt.Println(st)
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
// 0.txt
|
||||||
|
// foo_1.txt
|
||||||
|
}
|
||||||
|
|
||||||
func ExampleMultiGeneratorInOrder() {
|
func ExampleMultiGeneratorInOrder() {
|
||||||
gen1 := func(*nomino.Config) (string, error) {
|
gen1 := func(*nomino.Config) (string, error) {
|
||||||
return "hello", nil
|
return "hello", nil
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue