code: def constrained(constraints):
      """Decorator that puts constraints on the domain of f.
  
      >>> @constrained([lambda x: x > 0])
      ... def f(x): return x+1
      >>> f(1)
      2
      >>> f(0) #doctest:+SKIP
      Traceback (most recent call last):
      ...
      ConstraintViolation
      >>> len(f.constraints)
      1
  
      """
  
      def wrapper(f):
          @functions.wraps(f)
          def wrapped_f(*args, **kwargs):
              violations = [
                  c
                  for c in wrapped_f.constraints
                  if not c(*args, **kwargs)
              ]
              if violations:
                  raise ConstraintViolation(violations, *args, **kwargs)
              return f(*args, **kwargs)
  
          wrapped_f.constraints = constraints
          return wrapped_f
  
      return wrapper
  
file_path: optunity/wrappers/R/inst/optunity/constraints.py
imports: import functools
  from .None import functions
label_desc: Use image node_id 9 for calling a global function with example usage: constrained(constraints) and returns: wrapper, wrapped_f, f