diff --git a/testdata/calls.go b/testdata/calls.go index 6b4cd6eb..354a8a1c 100644 --- a/testdata/calls.go +++ b/testdata/calls.go @@ -4,6 +4,22 @@ type Thing struct { name string } +type ThingOption func(*Thing) + +func WithName(name string) ThingOption { + return func(t *Thing) { + t.name = name + } +} + +func NewThing(opts ...ThingOption) *Thing { + t := &Thing{} + for _, opt := range opts { + opt(t) + } + return t +} + func (t Thing) String() string { return t.name } @@ -36,6 +52,12 @@ func main() { runFunc(func(i int) { println("inside fp closure:", thing.String(), i) }, 3) + + // functional arguments + thingFunctionalArgs1 := NewThing() + thingFunctionalArgs1.Print("functional args 1") + thingFunctionalArgs2 := NewThing(WithName("named thing")) + thingFunctionalArgs2.Print("functional args 2") } func runFunc(f func(int), arg int) { diff --git a/testdata/calls.txt b/testdata/calls.txt index 6998aebf..61e19597 100644 --- a/testdata/calls.txt +++ b/testdata/calls.txt @@ -7,3 +7,5 @@ Thing.Print: foo arg: bar bound method: foo thing inside closure: foo inside fp closure: foo 3 +Thing.Print: arg: functional args 1 +Thing.Print: named thing arg: functional args 2