aspis.common.add_index_right

aspis.common.add_index_right(func, arr)[source]

Maps a function over the reversed sequence, passing both the index and the element to the function.

Parameters:
  • func (Callable[[T, int], U]) – A function that takes an element and its index as arguments and returns a transformed result.

  • arr (Sequence[T]) – The sequence to be mapped over.

Returns:

A new sequence with the results of the function applied to each element in reverse.

Return type:

Sequence[U]

Example

>>> add_index_right(lambda x, idx: f"{idx}: {x}", ["a", "b", "c"])
['2: c', '1: b', '0: a']