Codebase list golang-github-vbauerster-mpb / 85a05e7 decor / on_condition.go
85a05e7

Tree @85a05e7 (Download .tar.gz)

on_condition.go @85a05e7raw · history · blame

package decor

// OnPredicate returns decorator if predicate evaluates to true.
//
//	`decorator` Decorator
//
//	`predicate` func() bool
//
func OnPredicate(decorator Decorator, predicate func() bool) Decorator {
	if predicate() {
		return decorator
	}
	return nil
}

// OnCondition returns decorator if condition is true.
//
//	`decorator` Decorator
//
//	`cond` bool
//
func OnCondition(decorator Decorator, cond bool) Decorator {
	if cond {
		return decorator
	}
	return nil
}