def ensure_tuple(length, tuples):
    """Yield `length`-sized tuples from the given collection.
	
	Will truncate longer tuples to the desired length, and pad using the leading element if shorter.
	"""
    for elem in tuples:
        if not isinstance(elem, (tuple, list)):
            yield (elem,) * length
            continue
        l = len(elem)
        if l == length:
            yield elem
        elif l > length:
            yield tuple(elem[:length])
        elif l < length:
            yield (elem[0],) * (length - l) + tuple(elem)
