The filter Function
filter :: (a -> Bool) -> [a] -> [a]
filter f xs = [x | x <- xs, f x]ghci> filter squareGt100 [7..12]
[11,12]ghci> filter odd [1..5] -- get all odd numbers from a list
[1,3,5]
ghci> filter (\x -> length x > 2) ["a", "abc"] -- elements with length greater than 2
["abc"]
ghci> filter (\(x:xs) -> x == 'a') ["cardano", "ada"] -- elements staring with 'a'
["ada"]Last updated