-- |
-- Module      : Test.Speculate.Utils.Ord
-- Copyright   : (c) 2016-2019 Rudy Matela
-- License     : 3-Clause BSD  (see the file LICENSE)
-- Maintainer  : Rudy Matela <rudy@matela.com.br>
--
-- This module is part of Speculate.
--
-- Utilities for manipulating 'Ordering' values.
module Test.Speculate.Utils.Ord
  ( module Data.Ord
  , compareIndex
  )
where

import Data.Ord
import Data.List (elemIndex)

compareIndex :: Eq a => [a] -> a -> a -> Ordering
compareIndex :: forall a. Eq a => [a] -> a -> a -> Ordering
compareIndex [a]
xs a
x a
y =
  case (a -> [a] -> Maybe Int
forall a. Eq a => a -> [a] -> Maybe Int
elemIndex a
x [a]
xs, a -> [a] -> Maybe Int
forall a. Eq a => a -> [a] -> Maybe Int
elemIndex a
y [a]
xs) of
    (Just  Int
i, Just  Int
j) -> Int
i Int -> Int -> Ordering
forall a. Ord a => a -> a -> Ordering
`compare` Int
j
    (Maybe Int
Nothing, Just  Int
_) -> Ordering
GT
    (Just  Int
_, Maybe Int
Nothing) -> Ordering
LT
    (Maybe Int, Maybe Int)
_                  -> Ordering
EQ