Skip to content

pleroma.iteration

Predefined iteration strategies for use inside _iter_instances overrides.

pleroma.iteration.iter_all(instances)

Yields all instances in their original order.

This is the default traversal strategy and equivalent to the built-in :meth:~pleroma.MergeableMixin._iter_instances behaviour.

Parameters:

Name Type Description Default
instances Collection[T]

The collection of instances to iterate.

required

Returns:

Type Description
Iterator[T]

An iterator over all instances in original order.

pleroma.iteration.iter_reversed(instances)

Yields all instances in reverse order.

Parameters:

Name Type Description Default
instances Collection[T]

The collection of instances to iterate.

required

Returns:

Type Description
Iterator[T]

An iterator over all instances in reverse order.

pleroma.iteration.iter_first(instances)

Yields only the first two instances.

Limiting traversal to the first two ensures an actual merge takes place between position 0 and position 1 while discarding the rest.

Parameters:

Name Type Description Default
instances Collection[T]

The collection of instances to iterate.

required

Returns:

Type Description
Iterator[T]

An iterator over at most the first two instances.

pleroma.iteration.iter_last(instances)

Yields the first and the last instances.

Merges the base (position 0) with the tail (last position), skipping any intermediate instances.

Parameters:

Name Type Description Default
instances Collection[T]

The collection of instances to iterate.

required

Returns:

Type Description
Iterator[T]

An iterator over the first and last instances, or fewer if the collection has fewer than two elements.