code: def _map_generator(f, generator):
      
      item = next(generator)
      while True:
          try:
              result = yield f(item)
          except Exception:
              item = generator.throw(*sys.exc_info())
          else:
              item = generator.send(result)
docs: Apply ``f`` to the results of the given bi-directional generator.
  
      Unfortunately, generator comprehension (``f(x) for x in gen``) does not
      work for as expected for bi-directional generators. It won't send
      exceptions and results back.
  
      This function implements a map function for generators that sends values
      and exceptions back and forth as expected.