package
Version:
v0.0.6
Opens a new window with list of versions in this module.
Published: Aug 15, 2024
License: MIT
Opens a new window with license information.
Imports: 0
Opens a new window with list of imports.
Imported by: 0
Opens a new window with list of known importers.
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
}
Documentation
¶
func ApplyOr[T Setting[S], S any](d S, ss ...T) *S
ApplyOr is an apply settings with defaults
ApplyOrZero is an apply settings with defaults
type Setting[S any] func(*S)
Setting is a setting function for Apply
Source Files
¶
Click to show internal directories.
Click to hide internal directories.