docs: def iterate_by_type(objs, typelist):
      """
      collects a sequence of objs into buckets by type, then re-emits
      objs from the buckets, sorting through the buckets in the order
      specified by typelist. Any objects of a type not specified in
      typelist will be emitted last in no guaranteed order (but still
      grouped by type).
      """
  
      cache = collect_by_type(objs)
  
      for t in typelist:
          for val in cache.pop(t, tuple()):
              yield val
  
      for tl in cache.values():
          for val in tl:
              yield val