code: def _apply_to_data(data, func, unpack_dict=False):
      
      apply_ = partial(_apply_to_data, func=func, unpack_dict=unpack_dict)
  
      if isinstance(data, dict):
          if unpack_dict:
              return [apply_(v) for v in data.values()]
          return {k: apply_(v) for k, v in data.items()}
  
      if isinstance(data, (list, tuple)):
          try:
              # e.g.list/tuple of arrays
              return [apply_(x) for x in data]
          except TypeError:
              return func(data)
  
      return func(data)
docs: Apply a function to data, trying to unpack different data
      types.