def take(num):
    """Produce a sequence containing up to num elements from the head
    of the input sequence and no more.
    """
    def taker(input):
        p = num
        for elt in input:
            if p == 0:
                break

            yield elt
            p -= 1

    return taker