Skip to content

Commit

Permalink
added Compare classes to Ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
Carsten Csiky committed Dec 21, 2020
1 parent e1b1c9a commit 10dd0f1
Showing 1 changed file with 54 additions and 2 deletions.
56 changes: 54 additions & 2 deletions src/Type/Data/Ordering.purs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,30 @@ module Type.Data.Ordering
, class Invert
, invert
, class Equals
, class Compare
, compare
, class IsLt
, isLt
, class IsEq
, isEq
, class IsGt
, isGt
, class IsLte
, isLte
, class IsGte
, isGte
, equals
) where

import Prim.Ordering (LT, EQ, GT, Ordering) as PO
import Data.Ordering (Ordering(..))
import Type.Data.Boolean (True, False)
import Type.Proxy (Proxy(..))
import Data.Ordering (Ordering(..))
import Data.Symbol (SProxy)
import Prim.Ordering (Ordering, LT, EQ, GT)
import Prim.Symbol (class Compare) as Symbol
import Type.Data.Boolean (class Or, BProxy(..), False, True, Boolean)

-- | Value proxy for `Ordering` types
-- | **Deprecated:** Use `Type.Proxy` instead
Expand Down Expand Up @@ -71,5 +88,40 @@ instance equalsLTGT :: Equals PO.LT PO.GT False
instance equalsGTLT :: Equals PO.GT PO.LT False
instance equalsGTEQ :: Equals PO.GT PO.EQ False

equals :: forall proxy l r o. Equals l r o => proxy l -> proxy r -> Proxy o
equals _ _ = Proxy
-- | Compares type a b
class Compare a b (o :: Ordering) | a b -> o

compare :: forall a b o. Compare a b o => a -> b -> OProxy o
compare _ _ = OProxy

class IsLt a b (isLt :: Boolean) | a b -> isLt
instance isLtTrue ∷ (Compare a b o, Equals o LT isLt) => IsLt a b isLt

isLt :: forall a b isLt. IsLt a b isLt => a -> b -> BProxy isLt
isLt _ _ = BProxy

class IsGt a b (isGt :: Boolean) | a b -> isGt
instance isGtCompare :: (Compare a b o, Equals o GT isGt) => IsGt a b isGt

isGt :: forall a b isGt. IsGt a b isGt => a -> b -> BProxy isGt
isGt _ _ = BProxy

class IsEq a b (isEq :: Boolean) | a b -> isEq
instance isEqCompare :: (Compare a b o, Equals o EQ isEq) => IsEq a b isEq

isEq :: forall a b isEq. IsEq a b isEq => a -> b -> BProxy isEq
isEq _ _ = BProxy

class IsLte a b (isLte :: Boolean) | a b -> isLte
instance isLteFromIs ∷ (IsEq a b isEq, IsLt a b isLt, Or isEq isLt isLte) => IsLte a b isLte

isLte :: forall a b isLte. IsLte a b isLte => a -> b -> BProxy isLte
isLte _ _ = BProxy

class IsGte a b (isGte :: Boolean) | a b -> isGte
instance isGteFromIs :: (IsEq a b isEq, IsGt a b isGt, Or isEq isGt isGte) => IsGte a b isGte

isGte :: forall a b isGte. IsGte a b isGte => a -> b -> BProxy isGte
isGte _ _ = BProxy

instance compareOrd :: Symbol.Compare lhs rhs ord => Compare (SProxy lhs) (SProxy rhs) ord

0 comments on commit 10dd0f1

Please sign in to comment.