def doM(fun):
    """
    Takes a generator and unpacks values for every yield.

    Complexity: O(k) where k is the complexity of fun
    params:
        fun: the generator
    returns: the return value of the generator
    """
    def internal(value):
        """The step function"""
        try:
            res = fun.send(value).value
            return internal(res)
        except StopIteration:
            return value
    return internal(next(fun).value)