{-# LANGUAGE CPP, NoImplicitPrelude #-}
module Data.Foldable.Compat (
module Base
#if !(MIN_VERSION_base(4,8,0))
, length
, null
#endif
#if !(MIN_VERSION_base(4,10,0))
, maximumBy
, minimumBy
#endif
) where
#if MIN_VERSION_base(4,10,0)
import Data.Foldable as Base
#else
import Data.Foldable as Base hiding (maximumBy, minimumBy)
import Prelude (Ordering(..))
#endif
#if !(MIN_VERSION_base(4,8,0))
import Prelude (Bool(..), Int, (+))
null :: Foldable t => t a -> Bool
null = foldr (\_ _ -> False) True
length :: Foldable t => t a -> Int
length = foldl' (\c _ -> c+1) 0
#endif
#if !(MIN_VERSION_base(4,10,0))
maximumBy :: Foldable t => (a -> a -> Ordering) -> t a -> a
maximumBy cmp = foldl1 max'
where max' x y = case cmp x y of
GT -> x
_ -> y
minimumBy :: Foldable t => (a -> a -> Ordering) -> t a -> a
minimumBy cmp = foldl1 min'
where min' x y = case cmp x y of
GT -> y
_ -> x
#endif