module CabalGild.Unstable.Extra.List where

-- | Compares the length of the given list to the given integer. This is
-- equivalent to @compare (length xs) n@, but it can be more efficient if @n@
-- is less than @length xs@.
compareLength :: [a] -> Int -> Ordering
compareLength :: forall a. [a] -> Int -> Ordering
compareLength [a]
xs Int
n =
  if Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
0
    then Ordering
GT
    else case [a]
xs of
      [] -> Int -> Int -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Int
0 Int
n
      a
_ : [a]
ys -> [a] -> Int -> Ordering
forall a. [a] -> Int -> Ordering
compareLength [a]
ys (Int -> Ordering) -> Int -> Ordering
forall a b. (a -> b) -> a -> b
$ Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1