withReplaced

fun <T> Iterable<T>.withReplaced(t: T, block: (T) -> T): List<T>(source)

Returns a new list with the first occurrence of element t replaced by applying block to it. All other elements remain unchanged.

Return

A new list with the replaced element

Parameters

t

The element to replace

block

A function that transforms the found element

Type Parameters

T

The type of elements in the iterable