# iterable_like

compas.utilities.iterable_like(target, reference, fillvalue=None)[source]

Creates an iterator from a reference object with size equivalent to that of a target iterable.

Values will be yielded one at a time until the target iterable is exhausted. If target and reference are of uneven size, fillvalue will be used to substitute the missing values.

Parameters
• target (iterable) – An iterable to be matched in size.

• reference (iterable) – Iterable taken as basis for pairing.

• fillvalue (object, optional) – Defaults to None.

Returns

object – The next value in the iterator

Notes

This function can also produce an iterable capped to the size of target whenever the supplied reference is larger.

Examples

>>> keys = [0, 1, 2, 3]
>>> color = (255, 0, 0)
>>> list(iterable_like(keys, [color], color))
[(255, 0, 0), (255, 0, 0), (255, 0, 0), (255, 0, 0)]
>>> list(iterable_like(color, keys))
[0, 1, 2]