Skip to content

Prepare for 2.0 release #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 2, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
29 changes: 8 additions & 21 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 Prelude

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 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,18 +19,13 @@ 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)
Expand All @@ -53,7 +40,7 @@ instance applicativeFirst :: Applicative First where
pure = First <<< pure

instance bindFirst :: Bind First where
bind (First x) f = First (bind x (runFirst <<< f))
bind (First x) f = First (x >>= \y -> case f y of First ma -> ma)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be derivable.


instance monadFirst :: Monad First

Expand Down
29 changes: 8 additions & 21 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 Prelude

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 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,18 +19,13 @@ 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)
Expand All @@ -53,7 +40,7 @@ instance applicativeLast :: Applicative Last where
pure = Last <<< pure

instance bindLast :: Bind Last where
bind (Last x) f = Last (bind x (runLast <<< f))
bind (Last x) f = Last (x >>= \y -> case f y of Last ma -> ma)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same


instance monadLast :: Monad Last

Expand Down