Learning Haskell: How to remove an item from a List in Haskell

前端 未结 7 1087
伪装坚强ぢ
伪装坚强ぢ 2021-02-01 19:06

Trying to learn Haskell. I am trying to write a simple function to remove a number from a list without using built-in function (delete...I think). For the sake of simplicity, le

相关标签:
7条回答
  • 2021-02-01 19:45

    I wrote a function in just one line of code:

    remove element list = filter (\e -> e/=element) list
    

    For example:

    remove 5 [1..10]
    

    [1,2,3,4,6,7,8,9,10]

    remove 'b' ['a'..'f']
    

    "acdef"

    0 讨论(0)
提交回复
热议问题