module Euler.Util.Inf
( Inf
, fromList
, toList
) where
import Euler.Prelude hiding (toList)
import qualified Data.List.NonEmpty as NE
newtype Inf a = Inf (NonEmpty a)
instance Show a => Show (Inf a)
where
show (Inf (x :| _)) = "Inf (" <> show x <> ", ...)"
instance Ord a => Ord (Inf a)
where
compare = compare `on` infHead
instance Eq a => Eq (Inf a) where
(==) = (==) `on` infHead
fromList :: [a] -> Inf a
fromList xs = Inf $ NE.fromList xs
toList :: Inf a -> [a]
toList (Inf xs) = NE.toList xs
infHead :: Inf a -> a
infHead (Inf (x :| _)) = x