replaceInPlace

Replaces the first occurrence of needle by replacement in array if present. Modifies array.

Array
replaceInPlace
(
alias pred = "a == b"
Array
E
)
(
auto ref Array array
,,
)
if (
isDynamicArray!Array
)

Examples

1 auto arr = [1, 2, 3, 4, 2, 3];
2 
3 assert(arr.replaceInPlace(2, 7) == [1, 7, 3, 4, 2, 3]);
4 // The input array gets modified.
5 assert(arr == [1, 7, 3, 4, 2, 3]);
6 // Replaces only the first occurrence
7 assert(arr.replaceInPlace(2, 7) == [1, 7, 3, 4, 7, 3]);
8 
9 // Can be called with non-lvalues
10 assert([1, 2, 3].replaceInPlace(2, 7) == [1, 7, 3]);

Meta