code: def collect(pred, expr):
      """Collect terms in expression that match predicate
  
      >>> from datashader.datashape import Unit, dshape
      >>> predicate = lambda term: isinstance(term, Unit)
      >>> dshape = dshape('var * {value: int64, loc: 2 * int32}')
      >>> sorted(set(collect(predicate, dshape)), key=str)
      [Fixed(val=2), ctype("int32"), ctype("int64"), Var()]
      >>> from datashader.datashape import var, int64
      >>> sorted(set(collect(predicate, [var, int64])), key=str)
      [ctype("int64"), Var()]
      """
      if pred(expr):
          return [expr]
      if isinstance(expr, coretypes.Record):
          return chain.from_iterable(
              collect(pred, typ) for typ in expr.types
          )
      if isinstance(expr, coretypes.Mono):
          return chain.from_iterable(
              collect(pred, typ) for typ in expr.parameters
          )
      if isinstance(expr, (list, tuple)):
          return chain.from_iterable(
              collect(pred, item) for item in expr
          )
  
file_path: datashader/datashader/datashape/util/__init__.py
imports: from __future__ import print_function, division, absolute_import
  from itertools import chain
  import operator
  from ..None import py2help
  from ..None import parser
  from ..None import type_symbol_table
  from ..validation import validate
  from ..None import coretypes
label_desc: Use image node_id 4 for calling a global function with example usage: collect(pred, expr) and returns: list, chain, chain, chain