def all_equal(iterator, test=None):
    """if `test is None` do a straight equality test"""
    it = iter(iterator)
    if test is None:
        try:
            target = next(it)
            test = lambda x: x == target
        except StopIteration:
            return True
    for item in it:
        if not test(item):
            return False
    return True
