Skip to content

Commit b9fc801

Browse files
committed
lint
1 parent b34fb4d commit b9fc801

File tree

1 file changed

+19
-22
lines changed

1 file changed

+19
-22
lines changed

docs/rfcs/functional-composition-pattern.md

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ functions using a functional-option argument passed to
160160
func WithLogs(createLogs CreateLogsFunc, sl component.StabilityLevel) FactoryOption {
161161
return factoryOptionFunc(func(o *factoryImpl, cfgType component.Type) {
162162
o.CreateLogsFunc = createLogs
163-
o.LogsStabilityFunc = sl.Self
163+
o.LogsStabilityFunc = sl.Self // See (5) below
164164
})
165165
}
166166

@@ -218,20 +218,19 @@ func NewRateLimiterWithExtraFeature(rf ReserveRateFunc, ef ExtraFeatureFunc) Rat
218218
### 5. Constant-value Function Implementations
219219

220220
For types defined by simple values, especially for enumerated types,
221-
define a `Self()` method to act as the corresponding functional
222-
constant:
221+
define a `Self()` method to act as the corresponding value:
223222

224223
```go
225224
// Self returns itself.
226-
func (t Type) Self() Type {
225+
func (t Config) Self() Config {
227226
return t
228227
}
229228

230-
// TypeFunc is ...
231-
type TypeFunc func() Type
229+
// ConfigFunc is ...
230+
type ConfigFunc func() Config
232231

233-
// Type gets the type of the component created by this factory.
234-
func (f TypeFunc) Type() Type {
232+
// Config gets the type of the component created by this factory.
233+
func (f ConfigFunc) Config() Config {
235234
if f == nil {
236235
}
237236
return f()
@@ -243,24 +242,22 @@ For example, we can decompose, modify, and recompose a
243242
constant-valued Type and Config functions:
244243

245244
```go
246-
// Construct a factory, get its default default Config:
247-
originalFactory := somepackage.NewFactory()
248-
cfg := originalFactory.CreateDefaultConfig()
249-
250-
// ... Modify the config object somehow
251-
252-
// Pass cfg.Self as the default config function,
253-
// return a new factory using the modified config.
254-
return NewFactoryImpl(factory.Type().Self, cfg.Self)
245+
// Copy a factory from somepackage, modify its default config.
246+
func modifiedFactory() Factory {
247+
original := somepackage.NewFactory()
248+
cfg := original.CreateDefaultConfig()
249+
250+
// ... Modify the config object somehow,
251+
// pass cfg.Self as the default config function.
252+
return component.NewFactory(original.Type, cfg.Self)
253+
}
255254
```
256255

257256
## Examples
258257

259-
### Flexibility and Composition
260-
261-
This pattern enables composition scenarios by making it easy to
262-
compose and decompose interface values. For example, to wrap a
263-
`receiver.Factory` with a limiter of some sort:
258+
This pattern enables composition by making it easy to compose and
259+
decompose interface values. For example, to wrap a `receiver.Factory`
260+
with a limiter of some sort:
264261

265262
```go
266263
// Transform existing factories with cross-cutting concerns

0 commit comments

Comments
 (0)