replaceElemAt
lib.lists.replaceElemAt
Docs pulled from | This Revision | about 1 hour ago
Replaces a list's nth element with a new element
Inputs
list- Input list
idx- index to replace
newElem- new element to replace with
Type
replaceElemAt :: [a] -> Int -> a -> [a]
Examples
replaceElemAt usage example
lib.replaceElemAt` [1 2 3] 0 "a"
=> ["a" 2 3]
Noogle detected
Implementation
The following is the current implementation of this function.
replaceElemAt =
list: idx: newElem:
assert lib.assertMsg (idx >= 0 && idx < length list)
"'lists.replaceElemAt' called with index ${toString idx} on a list of size ${toString (length list)}";
genList (i: if i == idx then newElem else elemAt list i) (length list);