mirror of
https://github.com/hanzoai/yaegi.git
synced 2026-10-01 00:49:47 +00:00
26 lines
300 B
Go
26 lines
300 B
Go
package main
|
|
|
|
type Option interface {
|
|
apply()
|
|
}
|
|
|
|
func f(opts ...Option) {
|
|
for _, opt := range opts {
|
|
opt.apply()
|
|
}
|
|
}
|
|
|
|
type T struct{}
|
|
|
|
func (t *T) apply() { println("in apply") }
|
|
|
|
func main() {
|
|
opt := []Option{&T{}}
|
|
f(opt[0]) // works
|
|
f(opt...) // fails
|
|
}
|
|
|
|
// Output:
|
|
// in apply
|
|
// in apply
|