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

后端 未结 4 2016
情深已故
情深已故 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 00:58

    perhaps this does what you want (applied to the list of lists):

    replaceNth 1 (replaceNth 3 4 [3,3,3,3,3])

提交回复
热议问题