Codebase list golang-github-vbauerster-mpb / 7eee044
OnPredicated and OnCondition decorator wrappers Vladimir Bauer 4 years ago
1 changed file(s) with 27 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 package decor
1
2 // OnPredicate returns decorator if predicate evaluates to true.
3 //
4 // `decorator` Decorator
5 //
6 // `predicate` func() bool
7 //
8 func OnPredicate(decorator Decorator, predicate func() bool) Decorator {
9 if predicate() {
10 return decorator
11 }
12 return nil
13 }
14
15 // OnCondition returns decorator if condition is true.
16 //
17 // `decorator` Decorator
18 //
19 // `cond` bool
20 //
21 func OnCondition(decorator Decorator, cond bool) Decorator {
22 if cond {
23 return decorator
24 }
25 return nil
26 }