title: How to implement and call a function with another function as an optional argument (filter function)
body: <p>I'm trying to write a function with a function as an optional argument. I want to use the second function as a filter function </p>
  
  <pre><code>def func1(arg1, arg2, func2, arg4=None):
      # do something with args1,2
      # do something with arg4 if called
      # do something with func2 if called
  
  def func2(arg5):
      # do something
  
  func1(41, "hello there")
  </code></pre>
  
  <p>In the example above I haven't called func2 . I know I could use a decorator i.e.</p>
  
  <pre><code>def func1(arg1, arg2, func2, arg4=None):
      # do something with args1,2
      func2()
      # do something with arg4 if called
  
  def func2(arg5):
      # do something
  
  func1(41, "hello there")
  </code></pre>
  
  <p>I'm not sure how to implement or call an optional decorator though. I think the best way would be to make the argument to func2 an argument in func1, <code>func1(arg1,arg2,arg5=None,arg4=None)</code> and then in func1 I could have some logic like this:</p>
  
  <pre><code>def func1(arg1, arg2, arg5=None, arg4=None):
      # do something with args1,2
      if arg5 is not None:
          func2(arg5)
      # do something with arg4 if called
  
  def func2(arg5):
      # do something
  
  func1(41, "hello there")
  </code></pre>
  
  <p>Any suggestions would be much appreciated! </p>