Codebase list golang-github-vbauerster-mpb / 7dcc983
skip nil decorators Vladimir Bauer 4 years ago
1 changed file(s) with 11 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
99
1010 // BarOption is a func option to alter default behavior of a bar.
1111 type BarOption func(*bState)
12
13 func skipNil(decorators []decor.Decorator) (filtered []decor.Decorator) {
14 for _, d := range decorators {
15 if d != nil {
16 filtered = append(filtered, d)
17 }
18 }
19 return
20 }
1221
1322 func (s *bState) addDecorators(dest *[]decor.Decorator, decorators ...decor.Decorator) {
1423 type mergeWrapper interface {
2534 // AppendDecorators let you inject decorators to the bar's right side.
2635 func AppendDecorators(decorators ...decor.Decorator) BarOption {
2736 return func(s *bState) {
28 s.addDecorators(&s.aDecorators, decorators...)
37 s.addDecorators(&s.aDecorators, skipNil(decorators)...)
2938 }
3039 }
3140
3241 // PrependDecorators let you inject decorators to the bar's left side.
3342 func PrependDecorators(decorators ...decor.Decorator) BarOption {
3443 return func(s *bState) {
35 s.addDecorators(&s.pDecorators, decorators...)
44 s.addDecorators(&s.pDecorators, skipNil(decorators)...)
3645 }
3746 }
3847