Update a list of a list of elements in a single list?

后端 未结 4 2014
情深已故
情深已故 2021-01-26 00:34

I have some code which is designed to replace a value in a list

replaceNth n newVal (x:xs)
 | n == 0 = newVal:xs
 | otherwise = x:replaceNth (n-1) newVal xs
         


        
4条回答
  •  广开言路
    2021-01-26 01:06

    Make a function that applies a function to the nth element of a list instead. Then you can easily get what you want by composing that with itself and using const for the inner replacement.

提交回复
热议问题