Skip to content

Commit ed5d4eb

Browse files
committed
added Compare classes to Ordering
1 parent 82b343f commit ed5d4eb

File tree

1 file changed

+53
-2
lines changed

1 file changed

+53
-2
lines changed

src/Type/Data/Ordering.purs

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,26 @@ module Type.Data.Ordering
99
, class Invert
1010
, invert
1111
, class Equals
12+
, class Compare
13+
, compare
14+
, class IsLt
15+
, isLt
16+
, class IsEq
17+
, isEq
18+
, class IsGt
19+
, isGt
20+
, class IsLte
21+
, isLte
22+
, class IsGte
23+
, isGte
1224
, equals
1325
) where
1426

15-
import Prim.Ordering (kind Ordering, LT, EQ, GT)
1627
import Data.Ordering (Ordering(..))
17-
import Type.Data.Boolean (kind Boolean, True, False, BProxy(..))
28+
import Data.Symbol (SProxy)
29+
import Prim.Ordering (kind Ordering, LT, EQ, GT)
30+
import Prim.Symbol (class Compare) as Symbol
31+
import Type.Data.Boolean (class Or, BProxy(..), False, True, kind Boolean)
1832

1933
-- | Value proxy for `Ordering` types
2034
data OProxy (ordering :: Ordering) = OProxy
@@ -75,3 +89,40 @@ instance equalsGTEQ :: Equals GT EQ False
7589
equals :: forall l r o. Equals l r o => OProxy l -> OProxy r -> BProxy o
7690
equals _ _ = BProxy
7791

92+
-- | Compares type a b
93+
class Compare a b (o :: Ordering) | a b -> o
94+
95+
compare :: forall a b o. Compare a b o => a -> b -> OProxy o
96+
compare _ _ = OProxy
97+
98+
class IsLt a b (isLt :: Boolean) | a b -> isLt
99+
instance isLtTrue ∷ (Compare a b o, Equals o LT isLt) => IsLt a b isLt
100+
101+
isLt :: forall a b isLt. IsLt a b isLt => a -> b -> BProxy isLt
102+
isLt _ _ = BProxy
103+
104+
class IsGt a b (isGt :: Boolean) | a b -> isGt
105+
instance isGtCompare :: (Compare a b o, Equals o GT isGt) => IsGt a b isGt
106+
107+
isGt :: forall a b isGt. IsGt a b isGt => a -> b -> BProxy isGt
108+
isGt _ _ = BProxy
109+
110+
class IsEq a b (isEq :: Boolean) | a b -> isEq
111+
instance isEqCompare :: (Compare a b o, Equals o EQ isEq) => IsEq a b isEq
112+
113+
isEq :: forall a b isEq. IsEq a b isEq => a -> b -> BProxy isEq
114+
isEq _ _ = BProxy
115+
116+
class IsLte a b (isLte :: Boolean) | a b -> isLte
117+
instance isLteFromIs ∷ (IsEq a b isEq, IsLt a b isLt, Or isEq isLt isLte) => IsLte a b isLte
118+
119+
isLte :: forall a b isLte. IsLte a b isLte => a -> b -> BProxy isLte
120+
isLte _ _ = BProxy
121+
122+
class IsGte a b (isGte :: Boolean) | a b -> isGte
123+
instance isGteFromIs :: (IsEq a b isEq, IsGt a b isGt, Or isEq isGt isGte) => IsGte a b isGte
124+
125+
isGte :: forall a b isGte. IsGte a b isGte => a -> b -> BProxy isGte
126+
isGte _ _ = BProxy
127+
128+
instance compareOrd :: Symbol.Compare lhs rhs ord => Compare (SProxy lhs) (SProxy rhs) ord

0 commit comments

Comments
 (0)