les_iterables.augmenting module
Summary
Functions:
Generate a series from items, alternating with an alternate item. |
|
Yield an iterable followed by an item. |
|
Yield an iterable, conditionally followed by an item. |
|
Yield items, followed by ensured_item, if ensured_item is not already present. |
|
Extend an iterable by yielding items returned by a factory. |
|
Yield an item followed by an iterable. |
|
Conditionally yield an item, followed by an iterable. |
|
Repeat the first item from an iterable on the end. |
|
Generate a series from items, where the original items are separated by another item. |
Reference
- les_iterables.augmenting.repeat_first(iterable)[source]
Repeat the first item from an iterable on the end.
Example
>>> ''.join(repeat_first("ABDC")) "ABCDA"
Useful for making a closed cycle out of elements. If iterable is empty, the result will also be empty.
- Parameters:
items. (An iterable series of) –
- Yields:
All items from iterables, followed by the first item from iterable.
- les_iterables.augmenting.prepend_if(item, iterable, condition)[source]
Conditionally yield an item, followed by an iterable.
- les_iterables.augmenting.append_if(iterable, item, condition)[source]
Yield an iterable, conditionally followed by an item.
- les_iterables.augmenting.alternate_with(items, alternate_item)[source]
Generate a series from items, alternating with an alternate item.
items[0], alternate_item, items[1], alternate_item, … ,items[n - 1], alternate_item
The last item yielded will be alternate_item
- les_iterables.augmenting.separate_with(items, separator)[source]
Generate a series from items, where the original items are separated by another item.
items[0], separator, items[1], separator, items[2] … separator, items[n]
The last item yielded will be the last element of items.
- les_iterables.augmenting.ensure_contains(items, ensured_item)[source]
Yield items, followed by ensured_item, if ensured_item is not already present.
- les_iterables.augmenting.extend(iterable, item_factory=<function <lambda>>)[source]
Extend an iterable by yielding items returned by a factory.
- Parameters:
iterable – An iterable series of items to be extended.
items_factory – A zero-argument callable that will be invoked once for reach item requested beyond the end of iterator to create additional items as necessary.