CantainerOptional, BarOptional
Vladimir Bauer
5 years ago
| 4 | 4 |
"io"
|
| 5 | 5 |
|
| 6 | 6 |
"github.com/vbauerster/mpb/v5/decor"
|
|
7 |
"github.com/vbauerster/mpb/v5/internal"
|
| 7 | 8 |
)
|
| 8 | 9 |
|
| 9 | 10 |
// BarOption is a function option which changes the default behavior of a bar.
|
|
| 136 | 137 |
}
|
| 137 | 138 |
}
|
| 138 | 139 |
|
| 139 | |
// BarOptOn returns option when condition evaluates to true.
|
| 140 | |
func BarOptOn(option BarOption, condition func() bool) BarOption {
|
| 141 | |
if condition() {
|
|
140 |
// BarOptional will invoke provided option only when pick is true.
|
|
141 |
func BarOptional(option BarOption, pick bool) BarOption {
|
|
142 |
return BarOptOn(option, internal.Predicate(pick))
|
|
143 |
}
|
|
144 |
|
|
145 |
// BarOptOn will invoke provided option only when higher order predicate
|
|
146 |
// evaluates to true.
|
|
147 |
func BarOptOn(option BarOption, predicate func() bool) BarOption {
|
|
148 |
if predicate() {
|
| 142 | 149 |
return option
|
| 143 | 150 |
}
|
| 144 | 151 |
return nil
|
| 4 | 4 |
"io/ioutil"
|
| 5 | 5 |
"sync"
|
| 6 | 6 |
"time"
|
|
7 |
|
|
8 |
"github.com/vbauerster/mpb/v5/internal"
|
| 7 | 9 |
)
|
| 8 | 10 |
|
| 9 | 11 |
// ContainerOption is a function option which changes the default
|
|
| 92 | 94 |
}
|
| 93 | 95 |
}
|
| 94 | 96 |
|
| 95 | |
// ContainerOptOn returns option when condition evaluates to true.
|
| 96 | |
func ContainerOptOn(option ContainerOption, condition func() bool) ContainerOption {
|
| 97 | |
if condition() {
|
|
97 |
// ContainerOptional will invoke provided option only when pick is true.
|
|
98 |
func ContainerOptional(option ContainerOption, pick bool) ContainerOption {
|
|
99 |
return ContainerOptOn(option, internal.Predicate(pick))
|
|
100 |
}
|
|
101 |
|
|
102 |
// ContainerOptOn will invoke provided option only when higher order
|
|
103 |
// predicate evaluates to true.
|
|
104 |
func ContainerOptOn(option ContainerOption, predicate func() bool) ContainerOption {
|
|
105 |
if predicate() {
|
| 98 | 106 |
return option
|
| 99 | 107 |
}
|
| 100 | 108 |
return nil
|
|
0 |
package internal
|
|
1 |
|
|
2 |
func Predicate(pick bool) func() bool {
|
|
3 |
return func() bool { return pick }
|
|
4 |
}
|