-- remove all occurrences of values at the start of a list that satisfy the
-- given predicate function
ltrim :: (a -> Bool) -> [a] -> [a]
ltrim _ [] = []
ltrim f (x:xs) = if f x then
ltrim f xs
else
x:xs
-- remove all occurrences of values at the end of a list that satisfy the
-- given predicate function
rtrim :: (a -> Bool) -> [a] -> [a]
rtrim f lst = reverse (ltrim f (reverse lst))
-- remove all occurrences of values at the start/end of a list that satisfy the
-- given predicate function
trim :: (a -> Bool) -> [a] -> [a]
trim f lst = ltrim f (rtrim f lst)