aspis.common.adjust

aspis.common.adjust(idx, func, seq)[source]

Adjusts the element at the specified index in a sequence by applying a function to it.

Parameters:
  • idx (int) – The index of the element to adjust. This index must be within the range of the sequence.

  • func (Callable[[T], T]) – A function to apply to the element at the specified index. It takes the element as input and returns the modified element.

  • seq (Sequence[T]) – The sequence (list, tuple, or string) to modify.

Returns:

A new sequence with the element at the specified index modified.

Return type:

Sequence[T] | str

Example

>>> adjust(1, lambda x: x * 2, [1, 2, 3])
[1, 4, 3]
>>> adjust(0, str.upper, "hello")
'Hello'