class_docstr: Utility to apply a function or operation to all viewable elements
  inside the object.
class_docstr_tok: ["Utility","to","apply","a","function","or","operation","to","all","viewable","elements","inside","the","object","."]
docstr: Applies a function to all (Nd)Overlay or Element objects.
  
  Any keyword arguments are passed through to the function. If
  keyword arguments are instance parameters, or streams are
  supplied the returned object will dynamically update in
  response to changes in those objects.
  
  Args:
      apply_function: A callable function
          The function will be passed the return value of the
          DynamicMap as the first argument and any supplied
          stream values or keywords as additional keyword
          arguments.
      streams (list, optional): A list of Stream objects
          The Stream objects can dynamically supply values which
          will be passed to the function as keywords.
      link_inputs (bool, optional): Whether to link the inputs
          Determines whether Streams and Links attached to
          original object will be inherited.
      link_dataset (bool, optional): Whether to link the dataset
          Determines whether the dataset will be inherited.
      dynamic (bool, optional): Whether to make object dynamic
          By default object is made dynamic if streams are
          supplied, an instance parameter is supplied as a
          keyword argument, or the supplied function is a
          parameterized method.
      per_element (bool, optional): Whether to apply per element
          By default apply works on the leaf nodes, which
          includes both elements and overlays. If set it will
          apply directly to elements.
      kwargs (dict, optional): Additional keyword arguments
          Keyword arguments which will be supplied to the
          function.
  
  Returns:
      A new object where the function was applied to all
      contained (Nd)Overlay or Element objects.
docstr_tok: ["Applies","a","function","to","all","(","Nd",")","Overlay","or","Element","objects",".","Any","keyword","arguments","are","passed","through","to","the","function",".","If","keyword","arguments","are","instance","parameters",",","or","streams","are","supplied","the","returned","object","will","dynamically","update","in","response","to","changes","in","those","objects",".","Args",":","apply_function",":","A","callable","function","The","function","will","be","passed","the","return","value","of","the","DynamicMap","as","the","first","argument","and","any","supplied","stream","values","or","keywords","as","additional","keyword","arguments",".","streams","(","list",",","optional",")",":","A","list","of","Stream","objects","The","Stream","objects","can","dynamically","supply","values","which","will","be","passed","to","the","function","as","keywords",".","link_inputs","(","bool",",","optional",")",":","Whether","to","link","the","inputs","Determines","whether","Streams","and","Links","attached","to","original","object","will","be","inherited",".","link_dataset","(","bool",",","optional",")",":","Whether","to","link","the","dataset","Determines","whether","the","dataset","will","be","inherited",".","dynamic","(","bool",",","optional",")",":","Whether","to","make","object","dynamic","By","default","object","is","made","dynamic","if","streams","are","supplied",",","an","instance","parameter","is","supplied","as","a","keyword","argument",",","or","the","supplied","function","is","a","parameterized","method",".","per_element","(","bool",",","optional",")",":","Whether","to","apply","per","element","By","default","apply","works","on","the","leaf","nodes",",","which","includes","both","elements","and","overlays",".","If","set","it","will","apply","directly","to","elements",".","kwargs","(","dict",",","optional",")",":","Additional","keyword","arguments","Keyword","arguments","which","will","be","supplied","to","the","function",".","Returns",":","A","new","object","where","the","function","was","applied","to","all","contained","(","Nd",")","Overlay","or","Element","objects","."]
code: def __call__(
      self,
      apply_function,
      streams=None,
      link_inputs=True,
      link_dataset=True,
      dynamic=None,
      per_element=False,
      **kwargs,
  ):
      """Applies a function to all (Nd)Overlay or Element objects.
  
      Any keyword arguments are passed through to the function. If
      keyword arguments are instance parameters, or streams are
      supplied the returned object will dynamically update in
      response to changes in those objects.
  
      Args:
          apply_function: A callable function
              The function will be passed the return value of the
              DynamicMap as the first argument and any supplied
              stream values or keywords as additional keyword
              arguments.
          streams (list, optional): A list of Stream objects
              The Stream objects can dynamically supply values which
              will be passed to the function as keywords.
          link_inputs (bool, optional): Whether to link the inputs
              Determines whether Streams and Links attached to
              original object will be inherited.
          link_dataset (bool, optional): Whether to link the dataset
              Determines whether the dataset will be inherited.
          dynamic (bool, optional): Whether to make object dynamic
              By default object is made dynamic if streams are
              supplied, an instance parameter is supplied as a
              keyword argument, or the supplied function is a
              parameterized method.
          per_element (bool, optional): Whether to apply per element
              By default apply works on the leaf nodes, which
              includes both elements and overlays. If set it will
              apply directly to elements.
          kwargs (dict, optional): Additional keyword arguments
              Keyword arguments which will be supplied to the
              function.
  
      Returns:
          A new object where the function was applied to all
          contained (Nd)Overlay or Element objects.
      """
      from ..util import Dynamic
      from .data import Dataset
      from .dimension import ViewableElement
      from .element import Element
      from .spaces import DynamicMap, HoloMap
  
      if streams is None:
          streams = []
  
      if isinstance(self._obj, DynamicMap) and dynamic == False:
          samples = tuple(d.values for d in self._obj.kdims)
          if not all(samples):
              raise ValueError(
                  "Applying a function to a DynamicMap "
                  "and setting dynamic=False is only "
                  "possible if key dimensions define "
                  "a discrete parameter space."
              )
          if not len(samples):
              return self._obj[samples]
          return HoloMap(self._obj[samples]).apply(
              apply_function,
              streams,
              link_inputs,
              link_dataset,
              dynamic,
              per_element,
              **kwargs,
          )
  
      if isinstance(apply_function, str):
          args = kwargs.pop("_method_args", ())
          method_name = apply_function
  
          def apply_function(object, **kwargs):
              method = getattr(object, method_name, None)
              if method is None:
                  raise AttributeError(
                      "Applied method %s does not exist."
                      "When declaring a method to apply "
                      "as a string ensure a corresponding "
                      "method exists on the object." % method_name
                  )
              return method(*args, **kwargs)
  
      if "panel" in sys.modules:
          from panel.widgets.base import Widget
  
          kwargs = {
              k: v.param.value if isinstance(v, Widget) else v
              for k, v in kwargs.items()
          }
  
      spec = Element if per_element else ViewableElement
      applies = isinstance(self._obj, spec)
      params = {
          p: val
          for p, val in kwargs.items()
          if isinstance(val, param.Parameter)
          and isinstance(val.owner, param.Parameterized)
      }
  
      dependent_kws = any(
          (isinstance(val, FunctionType) and hasattr(val, "_dinfo"))
          or util.is_param_method(val, has_deps=True)
          for val in kwargs.values()
      )
  
      if dynamic is None:
          is_dynamic = (
              bool(streams)
              or isinstance(self._obj, DynamicMap)
              or util.is_param_method(apply_function, has_deps=True)
              or params
              or dependent_kws
          )
      else:
          is_dynamic = dynamic
  
      if (applies or isinstance(self._obj, HoloMap)) and is_dynamic:
          return Dynamic(
              self._obj,
              operation=apply_function,
              streams=streams,
              kwargs=kwargs,
              link_inputs=link_inputs,
              link_dataset=link_dataset,
          )
      elif applies:
          inner_kwargs = util.resolve_dependent_kwargs(kwargs)
          if hasattr(apply_function, "dynamic"):
              inner_kwargs["dynamic"] = False
          new_obj = apply_function(self._obj, **inner_kwargs)
          if (
              link_dataset
              and isinstance(self._obj, Dataset)
              and isinstance(new_obj, Dataset)
              and new_obj._dataset is None
          ):
              new_obj._dataset = self._obj.dataset
          return new_obj
      elif self._obj._deep_indexable:
          mapped = []
          for k, v in self._obj.data.items():
              new_val = v.apply(
                  apply_function,
                  dynamic=dynamic,
                  streams=streams,
                  link_inputs=link_inputs,
                  link_dataset=link_dataset,
                  **kwargs,
              )
              if new_val is not None:
                  mapped.append((k, new_val))
          return self._obj.clone(mapped, link=link_inputs)
  
imports: import copy
  import sys
  from functools import wraps
  from types import FunctionType
  import param
  from .None import util
  from .pprint import PrettyPrinter
label_desc: Use image node_id 2 for calling the Apply obj's underlying member method code with example usage: obj.__call__(apply_function, streams, link_inputs, link_dataset, dynamic, per_element) and returns: HoloMap, Dynamic, self, method, new_obj, self