Remove elements by index in haskell

后端 未结 8 895

I\'m new in haskell and I\'m looking for some standard functions to work with lists by indexes.

My exact problem is that i want to remove 3 elements after every 5. If i

8条回答
  •  一整个雨季
    2021-02-07 23:51

    You can count your elements easily:

    strip' (x:xs) n | n == 7 = strip' xs 0
                    | n >= 5 = strip' xs (n+1)
                    | n < 5 = x : strip' xs (n+1)
    strip l = strip' l 0
    

    Though open-coding looks shorter:

    strip (a:b:c:d:e:_:_:_:xs) = a:b:c:d:e:strip xs
    strip (a:b:c:d:e:xs) = a:b:c:d:e:[]
    strip xs = xs
    

提交回复
热议问题