code: def masked_collapse(termination, collapse=None, union=False):
      """extract mask from termination, and combine it with the given collapse
  
      termination is a termination condition, and collapse is a collapse dict
      """
      if collapse is None:
          collapse = {}
      masked = _masked_collapse(termination)
      masked = [
          (
              j,
              interval_overlap(
                  collapse.get(j, {}), masked.get(j, {}), union
              ),
          )
          for j in set(collapse.keys() + masked.keys())
      ]
      return dict((j, i) for (j, i) in masked if i)
  
imports: from functools import reduce
  from collections.abc import Callable
  from mystic._counter import Counter
  from itertools import permutations
  from dill.source import getblocks
  from dill.source import getsource
  from mystic.monitors import Monitor
  from mystic.monitors import VerboseMonitor
  from mystic.monitors import LoggingMonitor
  from mystic.monitors import CustomMonitor
  from mystic.monitors import Null
label_desc: Use image node_id 57 for calling a global function with example usage: masked_collapse(termination, collapse, union) and returns: dict