Util.hs (445B)
1 module Common.Util ((.:), count, consensus, untilFixed) where 2 3 (.:) :: (c -> d) -> (a -> b -> c) -> (a -> b -> d) 4 (f .: g) a b = f (g a b) 5 6 count :: (a -> Bool) -> [a] -> Int 7 count p = length . filter p 8 9 consensus :: (Eq a) => [a] -> Maybe a 10 consensus [] = Nothing 11 consensus (x : xs) = if all (== x) xs then Just x else Nothing 12 13 untilFixed :: (Eq a) => (a -> a) -> a -> a 14 untilFixed f x = let x' = f x in if x' == x then x' else untilFixed f x'