withReplacedAt

fun <T> Iterable<T>.withReplacedAt(i: Int, block: (T) -> T): List<T>(source)

Returns a new list with the element at index i replaced by applying block to it. All other elements remain unchanged.

Return

A new list with the replaced element

Parameters

i

The index of the element to replace

block

A function that transforms the element at the given index

Type Parameters

T

The type of elements in the iterable