Skip to content

Commit

Permalink
Merge pull request #22 from purescript/bump
Browse files Browse the repository at this point in the history
Prepare for 2.0 release
  • Loading branch information
garyb authored Oct 2, 2016
2 parents e4adaa3 + e3aaa6c commit bd1e507
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 95 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
"package.json"
],
"dependencies": {
"purescript-monoid": "^1.0.0"
"purescript-monoid": "^2.0.0"
}
}
26 changes: 4 additions & 22 deletions src/Data/Maybe.purs
Original file line number Diff line number Diff line change
@@ -1,26 +1,15 @@
module Data.Maybe where

import Prelude

import Control.Alt (class Alt)
import Control.Alternative (class Alternative)
import Control.Applicative (class Applicative)
import Control.Apply (class Apply)
import Control.Bind (class Bind)
import Control.Extend (class Extend)
import Control.Monad (class Monad)
import Control.MonadZero (class MonadZero)
import Control.Plus (class Plus)

import Data.Bounded (class Bounded, top)
import Data.Eq (class Eq, (==))
import Data.Function (const, id)
import Data.Functor (class Functor, (<$>))
import Data.Functor.Invariant (class Invariant, imapF)
import Data.Monoid (class Monoid)
import Data.Ord (class Ord, compare)
import Data.Ordering (Ordering(..))
import Data.Semigroup (class Semigroup, (<>))
import Data.Show (class Show, show)
import Data.Unit (Unit, unit)

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

-- | The `Ord` instance allows `Maybe` values to be compared with
-- | `compare`, `>`, `>=`, `<` and `<=` whenever there is an `Ord` instance for
-- | the type the `Maybe` contains.
-- |
-- | `Nothing` is considered to be less than any `Just` value.
instance ordMaybe :: Ord a => Ord (Maybe a) where
compare (Just x) (Just y) = compare x y
compare Nothing Nothing = EQ
compare Nothing _ = LT
compare _ Nothing = GT
derive instance ordMaybe :: Ord a => Ord (Maybe a)

instance boundedMaybe :: Bounded a => Bounded (Maybe a) where
top = Just top
Expand Down
53 changes: 17 additions & 36 deletions src/Data/Maybe/First.purs
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
module Data.Maybe.First where

import Control.Applicative (class Applicative, pure)
import Control.Apply (class Apply, (<*>))
import Control.Bind (class Bind, bind)
import Control.Extend (class Extend, extend)
import Control.Monad (class Monad)

import Data.Bounded (class Bounded, top, bottom)
import Data.Eq (class Eq, (==))
import Data.Function ((<<<))
import Data.Functor (class Functor, (<$>))
import Data.Functor.Invariant (class Invariant, imapF)
import Prelude

import Control.Extend (class Extend)

import Data.Functor.Invariant (class Invariant)
import Data.Maybe (Maybe(..))
import Data.Monoid (class Monoid)
import Data.Ord (class Ord, compare)
import Data.Semigroup (class Semigroup, (<>))
import Data.Show (class Show, show)
import Data.Newtype (class Newtype)

-- | Monoid returning the first (left-most) non-`Nothing` value.
-- |
Expand All @@ -27,38 +19,27 @@ import Data.Show (class Show, show)
-- | ```
newtype First a = First (Maybe a)

runFirst :: forall a. First a -> Maybe a
runFirst (First m) = m
derive instance newtypeFirst :: Newtype (First a) _

instance eqFirst :: (Eq a) => Eq (First a) where
eq (First x) (First y) = x == y
derive newtype instance eqFirst :: (Eq a) => Eq (First a)

instance ordFirst :: (Ord a) => Ord (First a) where
compare (First x) (First y) = compare x y
derive newtype instance ordFirst :: (Ord a) => Ord (First a)

instance boundedFirst :: (Bounded a) => Bounded (First a) where
top = First top
bottom = First bottom
derive newtype instance boundedFirst :: (Bounded a) => Bounded (First a)

instance functorFirst :: Functor First where
map f (First x) = First (f <$> x)
derive newtype instance functorFirst :: Functor First

instance invariantFirst :: Invariant First where
imap = imapF
derive newtype instance invariantFirst :: Invariant First

instance applyFirst :: Apply First where
apply (First f) (First x) = First (f <*> x)
derive newtype instance applyFirst :: Apply First

instance applicativeFirst :: Applicative First where
pure = First <<< pure
derive newtype instance applicativeFirst :: Applicative First

instance bindFirst :: Bind First where
bind (First x) f = First (bind x (runFirst <<< f))
derive newtype instance bindFirst :: Bind First

instance monadFirst :: Monad First
derive newtype instance monadFirst :: Monad First

instance extendFirst :: Extend First where
extend f (First x) = First (extend (f <<< First) x)
derive newtype instance extendFirst :: Extend First

instance showFirst :: (Show a) => Show (First a) where
show (First a) = "First (" <> show a <> ")"
Expand Down
53 changes: 17 additions & 36 deletions src/Data/Maybe/Last.purs
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
module Data.Maybe.Last where

import Control.Applicative (class Applicative, pure)
import Control.Apply (class Apply, (<*>))
import Control.Bind (class Bind, bind)
import Control.Extend (class Extend, extend)
import Control.Monad (class Monad)

import Data.Bounded (class Bounded, top, bottom)
import Data.Eq (class Eq, (==))
import Data.Function ((<<<))
import Data.Functor (class Functor, (<$>))
import Data.Functor.Invariant (class Invariant, imapF)
import Prelude

import Control.Extend (class Extend)

import Data.Functor.Invariant (class Invariant)
import Data.Maybe (Maybe(..))
import Data.Monoid (class Monoid)
import Data.Ord (class Ord, compare)
import Data.Semigroup (class Semigroup, (<>))
import Data.Show (class Show, show)
import Data.Newtype (class Newtype)

-- | Monoid returning the last (right-most) non-`Nothing` value.
-- |
Expand All @@ -27,38 +19,27 @@ import Data.Show (class Show, show)
-- | ```
newtype Last a = Last (Maybe a)

runLast :: forall a. Last a -> Maybe a
runLast (Last m) = m
derive instance newtypeLast :: Newtype (Last a) _

instance eqLast :: Eq a => Eq (Last a) where
eq (Last x) (Last y) = x == y
derive newtype instance eqLast :: (Eq a) => Eq (Last a)

instance ordLast :: Ord a => Ord (Last a) where
compare (Last x) (Last y) = compare x y
derive newtype instance ordLast :: (Ord a) => Ord (Last a)

instance boundedLast :: Bounded a => Bounded (Last a) where
top = Last top
bottom = Last bottom
derive newtype instance boundedLast :: (Bounded a) => Bounded (Last a)

instance functorLast :: Functor Last where
map f (Last x) = Last (f <$> x)
derive newtype instance functorLast :: Functor Last

instance invariantLast :: Invariant Last where
imap = imapF
derive newtype instance invariantLast :: Invariant Last

instance applyLast :: Apply Last where
apply (Last f) (Last x) = Last (f <*> x)
derive newtype instance applyLast :: Apply Last

instance applicativeLast :: Applicative Last where
pure = Last <<< pure
derive newtype instance applicativeLast :: Applicative Last

instance bindLast :: Bind Last where
bind (Last x) f = Last (bind x (runLast <<< f))
derive newtype instance bindLast :: Bind Last

instance monadLast :: Monad Last
derive newtype instance monadLast :: Monad Last

instance extendLast :: Extend Last where
extend f (Last x) = Last (extend (f <<< Last) x)
derive newtype instance extendLast :: Extend Last

instance showLast :: Show a => Show (Last a) where
show (Last a) = "(Last " <> show a <> ")"
Expand Down

0 comments on commit bd1e507

Please sign in to comment.