paya.util.iterables#

clampindex(index, numelems, absolute=False)#

Clamps an index, whether negative or positive, so that it remains within the range implied by numelems.

Parameters
  • index (int) – the index to clamp

  • numelems (int) – the number of elements in the iterable

  • absolute (bool) – clamp inside positive range

Returns

The clamped index.

Return type

int

index_in_range(index, numelems)#
Returns

True if the index is ‘legal’. Essentially a pre-emptive IndexError.

absindex(index, numelems, loop=False)#

Resolves a negative (reverse) index into a positive (forward) one.

Parameters
  • index (int) – the index to edit

  • numelems (int) – the number of elements in the iterable

  • loop (bool) – if this is False, and the index is out of range, IndexError will be raised; otherwise, the index will be wound over; defaults to False

Returns

The resolved index.

Return type

int

send_indices_relative(indicesToMove, refIndex, lst, after=True)#

Sends members at the specified indices into one contiguous block after refIndex. This is an in-place operation

Parameters
  • indicesToMove (list) – the indices to move

  • refIndex (int) – the reference index

  • lst (list) – the list

  • after (bool) – insert the indices after the reference index; defaults to True

Return type

None

send_indices_before(indicesToMove, refIndex, lst)#

Equivalent to send_indices_relative(after=False).

send_indices_after(indicesToMove, refIndex, lst)#

Equivalent to send_indices_relative(after=True).

nudge_index(index, lst, offset)#

Nudges an index in the direction and distance specified by ‘offset’.

Parameters
  • index (int) – the index of the member to nudge

  • lst (list) – the list to edit

  • offset (int) – the shift offset

Return type

None

nudge_indices(indices, lst, offset)#

Suitable for multi-selection list reordering. It clamps for out-of-range shifts, and maintains order within contiguous selection groups.

This is an in-place operation.

Parameters
  • indices (list of int) – the indices to nudge

  • lst (list) – the list to edit

  • offset (int) – the shift offset

Return type

None

without_duplicates(iterable)#
Parameters

iterable – the iterable to inspect

Returns

an order-preserved list of members in ‘iterable’, with duplicates omitted.

Return type

list