package
0.1.5
Repository: https://github.com/goexts/generic.git
Documentation: pkg.go.dev

# README

Settings

This is a simple example of using generics in Go.

Example

type Setting = settings.Setting[Serialize]

func WithValue(value string) Setting {
	return func(o *Serialize) {
		o.Value = value
	}
}

type Serialize struct {
	Value    string
}

var (
	defaultSerialize = Serialize{
		Value:    "hello",
}

func NewSerialize(ts ...Setting) *Serialize {
	serialize := settings.Apply(&defaultSerialize, ts)
	return serialize
}

func main() {
	serialize = NewSerialize()
	fmt.Println(serialize.Value)
	// Output: hello
	serialize := NewSerialize(WithValue("world"))
	fmt.Println(serialize.Value)
	// Output: world
}

# Functions

Apply is apply settings.
ApplyAny Applies a set of setting functions to a struct.
ApplyDefaults applies the given settings and default settings to the provided value.
ApplyDefaultsOr applies the given settings and default settings to the provided value.
ApplyDefaultsOrError applies the given settings and default settings to the provided value.
ApplyDefaultsOrZero applies the given settings and default settings to a zero value of the type.
ApplyErrorDefaults applies the given settings and default settings to the provided value.
ApplyErrorDefaultsOr applies the given settings and default settings to the provided value.
ApplyErrorDefaultsOrZero applies the given settings and default settings to a zero value of the type.
ApplyOr is an apply settings with defaults.
ApplyOrZero is an apply settings with defaults.

# Interfaces

No description provided by the author
Defaulter is an interface that provides a method to apply default settings.
ErrorDefaulter is an interface that provides a method to apply default settings and return an error.
No description provided by the author

# Type aliases

ApplyFunc is a ApplyFunc function for Apply.