<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _map_generator(f, generator):
 """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. """

    item = next(generator)
    while True:
        try:
            result = yield f(item)
        except Exception:
            item = generator.throw(*sys.exc_info())
        else:
            item = generator.send(result)