Skip to content

Commit e3aaa6c

Browse files
committed
newtype derive more stuff!
1 parent a29b248 commit e3aaa6c

File tree

2 files changed

+21
-33
lines changed

2 files changed

+21
-33
lines changed

src/Data/Maybe/First.purs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ module Data.Maybe.First where
22

33
import Prelude
44

5-
import Control.Extend (class Extend, extend)
5+
import Control.Extend (class Extend)
66

7-
import Data.Functor.Invariant (class Invariant, imapF)
7+
import Data.Functor.Invariant (class Invariant)
88
import Data.Maybe (Maybe(..))
99
import Data.Monoid (class Monoid)
1010
import Data.Newtype (class Newtype)
@@ -27,25 +27,19 @@ derive newtype instance ordFirst :: (Ord a) => Ord (First a)
2727

2828
derive newtype instance boundedFirst :: (Bounded a) => Bounded (First a)
2929

30-
instance functorFirst :: Functor First where
31-
map f (First x) = First (f <$> x)
30+
derive newtype instance functorFirst :: Functor First
3231

33-
instance invariantFirst :: Invariant First where
34-
imap = imapF
32+
derive newtype instance invariantFirst :: Invariant First
3533

36-
instance applyFirst :: Apply First where
37-
apply (First f) (First x) = First (f <*> x)
34+
derive newtype instance applyFirst :: Apply First
3835

39-
instance applicativeFirst :: Applicative First where
40-
pure = First <<< pure
36+
derive newtype instance applicativeFirst :: Applicative First
4137

42-
instance bindFirst :: Bind First where
43-
bind (First x) f = First (x >>= \y -> case f y of First ma -> ma)
38+
derive newtype instance bindFirst :: Bind First
4439

45-
instance monadFirst :: Monad First
40+
derive newtype instance monadFirst :: Monad First
4641

47-
instance extendFirst :: Extend First where
48-
extend f (First x) = First (extend (f <<< First) x)
42+
derive newtype instance extendFirst :: Extend First
4943

5044
instance showFirst :: (Show a) => Show (First a) where
5145
show (First a) = "First (" <> show a <> ")"

src/Data/Maybe/Last.purs

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ module Data.Maybe.Last where
22

33
import Prelude
44

5-
import Control.Extend (class Extend, extend)
5+
import Control.Extend (class Extend)
66

7-
import Data.Functor.Invariant (class Invariant, imapF)
7+
import Data.Functor.Invariant (class Invariant)
88
import Data.Maybe (Maybe(..))
99
import Data.Monoid (class Monoid)
1010
import Data.Newtype (class Newtype)
@@ -21,31 +21,25 @@ newtype Last a = Last (Maybe a)
2121

2222
derive instance newtypeLast :: Newtype (Last a) _
2323

24-
derive newtype instance eqLast :: Eq a => Eq (Last a)
24+
derive newtype instance eqLast :: (Eq a) => Eq (Last a)
2525

26-
derive newtype instance ordLast :: Ord a => Ord (Last a)
26+
derive newtype instance ordLast :: (Ord a) => Ord (Last a)
2727

28-
derive newtype instance boundedLast :: Bounded a => Bounded (Last a)
28+
derive newtype instance boundedLast :: (Bounded a) => Bounded (Last a)
2929

30-
instance functorLast :: Functor Last where
31-
map f (Last x) = Last (f <$> x)
30+
derive newtype instance functorLast :: Functor Last
3231

33-
instance invariantLast :: Invariant Last where
34-
imap = imapF
32+
derive newtype instance invariantLast :: Invariant Last
3533

36-
instance applyLast :: Apply Last where
37-
apply (Last f) (Last x) = Last (f <*> x)
34+
derive newtype instance applyLast :: Apply Last
3835

39-
instance applicativeLast :: Applicative Last where
40-
pure = Last <<< pure
36+
derive newtype instance applicativeLast :: Applicative Last
4137

42-
instance bindLast :: Bind Last where
43-
bind (Last x) f = Last (x >>= \y -> case f y of Last ma -> ma)
38+
derive newtype instance bindLast :: Bind Last
4439

45-
instance monadLast :: Monad Last
40+
derive newtype instance monadLast :: Monad Last
4641

47-
instance extendLast :: Extend Last where
48-
extend f (Last x) = Last (extend (f <<< Last) x)
42+
derive newtype instance extendLast :: Extend Last
4943

5044
instance showLast :: Show a => Show (Last a) where
5145
show (Last a) = "(Last " <> show a <> ")"

0 commit comments

Comments
 (0)