aoc2025

Advent of Code 2025
git clone git://git.rr3.xyz/aoc2025
Log | Files | Refs | Submodules

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'