summaryrefslogtreecommitdiff
path: root/pkg/x/option.go
blob: b0bf6381b1c0228185a2a0e92f9e4595ae020a84 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package x

type Configure[T any] func(T)
type Option[T any] func(T) T
type Factory[T any] func() T

func New[T any](options ...Option[T]) T {
	item := Default[T]()
	for _, option := range options {
		item = option(item)
	}
	return item
}

func With[T any](with Configure[T]) Option[T] {
	return func(item T) T {
		with(item)
		return item
	}
}