Skip to content

Commit a43f03c

Browse files
authored
Merge pull request #27 from purescript/eq-ord-1
Add `Eq1` and `Ord1` instances
2 parents 299f5e5 + 1baefa5 commit a43f03c

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

bower.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"package.json"
1818
],
1919
"dependencies": {
20-
"purescript-monoid": "^2.0.0"
20+
"purescript-monoid": "^2.2.0",
21+
"purescript-prelude": "^2.4.0"
2122
}
2223
}

src/Data/Maybe.purs

+6
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ import Control.Extend (class Extend)
88
import Control.MonadZero (class MonadZero)
99
import Control.Plus (class Plus)
1010

11+
import Data.Eq (class Eq1)
1112
import Data.Functor.Invariant (class Invariant, imapF)
1213
import Data.Monoid (class Monoid)
14+
import Data.Ord (class Ord1)
1315

1416
-- | The `Maybe` type is used to represent optional values and can be seen as
1517
-- | something like a type-safe `null`, where `Nothing` is `null` and `Just x`
@@ -184,13 +186,17 @@ instance monoidMaybe :: Semigroup a => Monoid (Maybe a) where
184186
-- | type the `Maybe` contains.
185187
derive instance eqMaybe :: Eq a => Eq (Maybe a)
186188

189+
instance eq1Maybe :: Eq1 Maybe where eq1 = eq
190+
187191
-- | The `Ord` instance allows `Maybe` values to be compared with
188192
-- | `compare`, `>`, `>=`, `<` and `<=` whenever there is an `Ord` instance for
189193
-- | the type the `Maybe` contains.
190194
-- |
191195
-- | `Nothing` is considered to be less than any `Just` value.
192196
derive instance ordMaybe :: Ord a => Ord (Maybe a)
193197

198+
instance ord1Maybe :: Ord1 Maybe where compare1 = compare
199+
194200
instance boundedMaybe :: Bounded a => Bounded (Maybe a) where
195201
top = Just top
196202
bottom = Nothing

src/Data/Maybe/First.purs

+6
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ import Prelude
44

55
import Control.Extend (class Extend)
66

7+
import Data.Eq (class Eq1)
78
import Data.Functor.Invariant (class Invariant)
89
import Data.Maybe (Maybe(..))
910
import Data.Monoid (class Monoid)
1011
import Data.Newtype (class Newtype)
12+
import Data.Ord (class Ord1)
1113

1214
-- | Monoid returning the first (left-most) non-`Nothing` value.
1315
-- |
@@ -23,8 +25,12 @@ derive instance newtypeFirst :: Newtype (First a) _
2325

2426
derive newtype instance eqFirst :: (Eq a) => Eq (First a)
2527

28+
derive newtype instance eq1First :: Eq1 First
29+
2630
derive newtype instance ordFirst :: (Ord a) => Ord (First a)
2731

32+
derive newtype instance ord1First :: Ord1 First
33+
2834
derive newtype instance boundedFirst :: (Bounded a) => Bounded (First a)
2935

3036
derive newtype instance functorFirst :: Functor First

src/Data/Maybe/Last.purs

+6
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ import Prelude
44

55
import Control.Extend (class Extend)
66

7+
import Data.Eq (class Eq1)
78
import Data.Functor.Invariant (class Invariant)
89
import Data.Maybe (Maybe(..))
910
import Data.Monoid (class Monoid)
1011
import Data.Newtype (class Newtype)
12+
import Data.Ord (class Ord1)
1113

1214
-- | Monoid returning the last (right-most) non-`Nothing` value.
1315
-- |
@@ -23,8 +25,12 @@ derive instance newtypeLast :: Newtype (Last a) _
2325

2426
derive newtype instance eqLast :: (Eq a) => Eq (Last a)
2527

28+
derive newtype instance eq1Last :: Eq1 Last
29+
2630
derive newtype instance ordLast :: (Ord a) => Ord (Last a)
2731

32+
derive newtype instance ord1Last :: Ord1 Last
33+
2834
derive newtype instance boundedLast :: (Bounded a) => Bounded (Last a)
2935

3036
derive newtype instance functorLast :: Functor Last

0 commit comments

Comments
 (0)