code: def _update_masks(condition, mask, kind="", new=False):
      """update the termination condition with the given mask"""
      kind = kind if kind else "Collapse"
      if isinstance(
          condition, tuple
      ):  # mystic.termination.When is tuple
          conditions = ()  # XXX: faster using list?
          for term in condition:
              termdoc = (
                  term.__doc__
              )  # or 'MISSING' #FIXME: shouldn't be missing
              if isinstance(term, tuple) or termdoc.startswith(kind):
                  term = _update_masks(term, mask, kind, new)
              conditions += (term,)
          return type(condition)(*conditions)
      # else: get dict used to build termination condition
      if new:
          return _replace_mask(condition, mask)
      return _extend_mask(condition, mask)
  
file_path: mystic/mystic/mask.py
imports: import mystic.termination
label_desc: Use image node_id 3 for calling a global function with example usage: _update_masks(condition, mask, kind, new) and returns: _extend_mask, type, _replace_mask