Skip to content

Commit a29b248

Browse files
committed
Prepare for 2.0 release
1 parent e4adaa3 commit a29b248

File tree

4 files changed

+21
-65
lines changed

4 files changed

+21
-65
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717
"package.json"
1818
],
1919
"dependencies": {
20-
"purescript-monoid": "^1.0.0"
20+
"purescript-monoid": "^2.0.0"
2121
}
2222
}

src/Data/Maybe.purs

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,15 @@
11
module Data.Maybe where
22

3+
import Prelude
4+
35
import Control.Alt (class Alt)
46
import Control.Alternative (class Alternative)
5-
import Control.Applicative (class Applicative)
6-
import Control.Apply (class Apply)
7-
import Control.Bind (class Bind)
87
import Control.Extend (class Extend)
9-
import Control.Monad (class Monad)
108
import Control.MonadZero (class MonadZero)
119
import Control.Plus (class Plus)
1210

13-
import Data.Bounded (class Bounded, top)
14-
import Data.Eq (class Eq, (==))
15-
import Data.Function (const, id)
16-
import Data.Functor (class Functor, (<$>))
1711
import Data.Functor.Invariant (class Invariant, imapF)
1812
import Data.Monoid (class Monoid)
19-
import Data.Ord (class Ord, compare)
20-
import Data.Ordering (Ordering(..))
21-
import Data.Semigroup (class Semigroup, (<>))
22-
import Data.Show (class Show, show)
23-
import Data.Unit (Unit, unit)
2413

2514
-- | The `Maybe` type is used to represent optional values and can be seen as
2615
-- | something like a type-safe `null`, where `Nothing` is `null` and `Just x`
@@ -193,21 +182,14 @@ instance monoidMaybe :: Semigroup a => Monoid (Maybe a) where
193182
-- | The `Eq` instance allows `Maybe` values to be checked for equality with
194183
-- | `==` and inequality with `/=` whenever there is an `Eq` instance for the
195184
-- | type the `Maybe` contains.
196-
instance eqMaybe :: Eq a => Eq (Maybe a) where
197-
eq Nothing Nothing = true
198-
eq (Just a1) (Just a2) = a1 == a2
199-
eq _ _ = false
185+
derive instance eqMaybe :: Eq a => Eq (Maybe a)
200186

201187
-- | The `Ord` instance allows `Maybe` values to be compared with
202188
-- | `compare`, `>`, `>=`, `<` and `<=` whenever there is an `Ord` instance for
203189
-- | the type the `Maybe` contains.
204190
-- |
205191
-- | `Nothing` is considered to be less than any `Just` value.
206-
instance ordMaybe :: Ord a => Ord (Maybe a) where
207-
compare (Just x) (Just y) = compare x y
208-
compare Nothing Nothing = EQ
209-
compare Nothing _ = LT
210-
compare _ Nothing = GT
192+
derive instance ordMaybe :: Ord a => Ord (Maybe a)
211193

212194
instance boundedMaybe :: Bounded a => Bounded (Maybe a) where
213195
top = Just top

src/Data/Maybe/First.purs

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
11
module Data.Maybe.First where
22

3-
import Control.Applicative (class Applicative, pure)
4-
import Control.Apply (class Apply, (<*>))
5-
import Control.Bind (class Bind, bind)
3+
import Prelude
4+
65
import Control.Extend (class Extend, extend)
7-
import Control.Monad (class Monad)
86

9-
import Data.Bounded (class Bounded, top, bottom)
10-
import Data.Eq (class Eq, (==))
11-
import Data.Function ((<<<))
12-
import Data.Functor (class Functor, (<$>))
137
import Data.Functor.Invariant (class Invariant, imapF)
148
import Data.Maybe (Maybe(..))
159
import Data.Monoid (class Monoid)
16-
import Data.Ord (class Ord, compare)
17-
import Data.Semigroup (class Semigroup, (<>))
18-
import Data.Show (class Show, show)
10+
import Data.Newtype (class Newtype)
1911

2012
-- | Monoid returning the first (left-most) non-`Nothing` value.
2113
-- |
@@ -27,18 +19,13 @@ import Data.Show (class Show, show)
2719
-- | ```
2820
newtype First a = First (Maybe a)
2921

30-
runFirst :: forall a. First a -> Maybe a
31-
runFirst (First m) = m
22+
derive instance newtypeFirst :: Newtype (First a) _
3223

33-
instance eqFirst :: (Eq a) => Eq (First a) where
34-
eq (First x) (First y) = x == y
24+
derive newtype instance eqFirst :: (Eq a) => Eq (First a)
3525

36-
instance ordFirst :: (Ord a) => Ord (First a) where
37-
compare (First x) (First y) = compare x y
26+
derive newtype instance ordFirst :: (Ord a) => Ord (First a)
3827

39-
instance boundedFirst :: (Bounded a) => Bounded (First a) where
40-
top = First top
41-
bottom = First bottom
28+
derive newtype instance boundedFirst :: (Bounded a) => Bounded (First a)
4229

4330
instance functorFirst :: Functor First where
4431
map f (First x) = First (f <$> x)
@@ -53,7 +40,7 @@ instance applicativeFirst :: Applicative First where
5340
pure = First <<< pure
5441

5542
instance bindFirst :: Bind First where
56-
bind (First x) f = First (bind x (runFirst <<< f))
43+
bind (First x) f = First (x >>= \y -> case f y of First ma -> ma)
5744

5845
instance monadFirst :: Monad First
5946

src/Data/Maybe/Last.purs

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
11
module Data.Maybe.Last where
22

3-
import Control.Applicative (class Applicative, pure)
4-
import Control.Apply (class Apply, (<*>))
5-
import Control.Bind (class Bind, bind)
3+
import Prelude
4+
65
import Control.Extend (class Extend, extend)
7-
import Control.Monad (class Monad)
86

9-
import Data.Bounded (class Bounded, top, bottom)
10-
import Data.Eq (class Eq, (==))
11-
import Data.Function ((<<<))
12-
import Data.Functor (class Functor, (<$>))
137
import Data.Functor.Invariant (class Invariant, imapF)
148
import Data.Maybe (Maybe(..))
159
import Data.Monoid (class Monoid)
16-
import Data.Ord (class Ord, compare)
17-
import Data.Semigroup (class Semigroup, (<>))
18-
import Data.Show (class Show, show)
10+
import Data.Newtype (class Newtype)
1911

2012
-- | Monoid returning the last (right-most) non-`Nothing` value.
2113
-- |
@@ -27,18 +19,13 @@ import Data.Show (class Show, show)
2719
-- | ```
2820
newtype Last a = Last (Maybe a)
2921

30-
runLast :: forall a. Last a -> Maybe a
31-
runLast (Last m) = m
22+
derive instance newtypeLast :: Newtype (Last a) _
3223

33-
instance eqLast :: Eq a => Eq (Last a) where
34-
eq (Last x) (Last y) = x == y
24+
derive newtype instance eqLast :: Eq a => Eq (Last a)
3525

36-
instance ordLast :: Ord a => Ord (Last a) where
37-
compare (Last x) (Last y) = compare x y
26+
derive newtype instance ordLast :: Ord a => Ord (Last a)
3827

39-
instance boundedLast :: Bounded a => Bounded (Last a) where
40-
top = Last top
41-
bottom = Last bottom
28+
derive newtype instance boundedLast :: Bounded a => Bounded (Last a)
4229

4330
instance functorLast :: Functor Last where
4431
map f (Last x) = Last (f <$> x)
@@ -53,7 +40,7 @@ instance applicativeLast :: Applicative Last where
5340
pure = Last <<< pure
5441

5542
instance bindLast :: Bind Last where
56-
bind (Last x) f = Last (bind x (runLast <<< f))
43+
bind (Last x) f = Last (x >>= \y -> case f y of Last ma -> ma)
5744

5845
instance monadLast :: Monad Last
5946

0 commit comments

Comments
 (0)