11module 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 )
6- import Control.Extend (class Extend , extend )
7- import Control.Monad (class Monad )
8-
9- import Data.Bounded (class Bounded , top , bottom )
10- import Data.Eq (class Eq , (==))
11- import Data.Function ((<<<))
12- import Data.Functor (class Functor , (<$>))
13- import Data.Functor.Invariant (class Invariant , imapF )
3+ import Prelude
4+
5+ import Control.Extend (class Extend )
6+
7+ import Data.Functor.Invariant (class Invariant )
148import Data.Maybe (Maybe (..))
159import 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,38 +19,27 @@ import Data.Show (class Show, show)
2719-- | ```
2820newtype 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
43- instance functorFirst :: Functor First where
44- map f (First x) = First (f <$> x)
30+ derive newtype instance functorFirst :: Functor First
4531
46- instance invariantFirst :: Invariant First where
47- imap = imapF
32+ derive newtype instance invariantFirst :: Invariant First
4833
49- instance applyFirst :: Apply First where
50- apply (First f) (First x) = First (f <*> x)
34+ derive newtype instance applyFirst :: Apply First
5135
52- instance applicativeFirst :: Applicative First where
53- pure = First <<< pure
36+ derive newtype instance applicativeFirst :: Applicative First
5437
55- instance bindFirst :: Bind First where
56- bind (First x) f = First (bind x (runFirst <<< f))
38+ derive newtype instance bindFirst :: Bind First
5739
58- instance monadFirst :: Monad First
40+ derive newtype instance monadFirst :: Monad First
5941
60- instance extendFirst :: Extend First where
61- extend f (First x) = First (extend (f <<< First ) x)
42+ derive newtype instance extendFirst :: Extend First
6243
6344instance showFirst :: (Show a ) => Show (First a ) where
6445 show (First a) = " First (" <> show a <> " )"
0 commit comments