(Generic) Functional Options Pattern
#Go #Generics #FunctionalPatternTargeted Go version: 1.18
Author(s): Changkun Ou
Permalink: https://golang.design/research/generic-option
The widely used self-referential function pattern as options, originally proposed by Rob Pike1, allows us to design a flexible set of APIs to help arbitrary configurations and initialization of a struct. However, when such a pattern is cumbersome when we use one option to support multiple types. This article investigates how the latest Go generics design could empower a refreshed “generic” functional options pattern and show what improvements in the future version of Go could better support such a pattern.
Read more...