Skip to content

Instantly share code, notes, and snippets.

@rexcfnghk
Created April 28, 2019 07:49
Show Gist options
  • Save rexcfnghk/054ba5fb93136db41b69607eae228d0b to your computer and use it in GitHub Desktop.
Save rexcfnghk/054ba5fb93136db41b69607eae228d0b to your computer and use it in GitHub Desktop.
add :: a -> [a] -> [a]
add x xs = x : xs
-- it is more common to write as
-- add = (:)
remove :: (Eq a) => a -> [a] -> [a]
remove _ [] = []
remove t (x:xs) = if t == x then remove t xs else remove t (x:xs)
-- you can also write it as a fold
-- remove t = foldr (\x xs -> if x == t then xs else x:xs) []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment