diff --git a/.gitignore b/.gitignore index 2836c9a..307f9c0 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,3 @@ /bower_components/ /node_modules/ /output/ -/tmp/ diff --git a/.travis.yml b/.travis.yml index 791313a..fc51ebf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: node_js -sudo: false -node_js: - - 0.10 +sudo: required +dist: trusty +node_js: 5 env: - PATH=$HOME/purescript:$PATH install: @@ -9,6 +9,15 @@ install: - wget -O $HOME/purescript.tar.gz https://github.com/purescript/purescript/releases/download/$TAG/linux64.tar.gz - tar -xvf $HOME/purescript.tar.gz -C $HOME/ - chmod a+x $HOME/purescript + - npm install -g bower - npm install script: - npm run build +after_success: +- >- + test $TRAVIS_TAG && + psc-publish > .pursuit.json && + curl -X POST http://pursuit.purescript.org/packages \ + -d @.pursuit.json \ + -H 'Accept: application/json' \ + -H "Authorization: token ${GITHUB_TOKEN}" diff --git a/README.md b/README.md index ff18f3b..aa910e5 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ [![Build Status](https://travis-ci.org/purescript/purescript-maybe.svg?branch=master)](https://travis-ci.org/purescript/purescript-maybe) [![Dependency Status](https://www.versioneye.com/user/projects/55848c22363861001d000326/badge.svg?style=flat)](https://www.versioneye.com/user/projects/55848c22363861001d000326) -Optional values. +Optional values. `Maybe` is often used to capture failures and in cases where nullable values might otherwise have been used in other languages. ## Installation @@ -12,12 +12,6 @@ Optional values. bower install purescript-maybe ``` -## Module documentation +## Documentation -- [Data.Maybe](docs/Data/Maybe.md) -- [Data.Maybe.Unsafe](docs/Data/Maybe/Unsafe.md) - -### Maybe monoids - -- [Data.Maybe.First](docs/Data/Maybe/First.md) -- [Data.Maybe.Last](docs/Data/Maybe/Last.md) +Module documentation is [published on Pursuit](http://pursuit.purescript.org/packages/purescript-maybe). diff --git a/bower.json b/bower.json index 6895c96..255dbaa 100644 --- a/bower.json +++ b/bower.json @@ -2,9 +2,6 @@ "name": "purescript-maybe", "homepage": "https://github.com/purescript/purescript-maybe", "description": "Optional values", - "keywords": [ - "purescript" - ], "license": "MIT", "repository": { "type": "git", @@ -17,10 +14,9 @@ "output", "test", "bower.json", - "gulpfile.js", "package.json" ], "dependencies": { - "purescript-monoid": "^0.3.0" + "purescript-monoid": "^1.0.0-rc.1" } } diff --git a/docs/Data/Maybe.md b/docs/Data/Maybe.md deleted file mode 100644 index cc63369..0000000 --- a/docs/Data/Maybe.md +++ /dev/null @@ -1,121 +0,0 @@ -## Module Data.Maybe - -#### `Maybe` - -``` purescript -data Maybe a - = Nothing - | Just a -``` - -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` -is the non-null value `x`. - -##### Instances -``` purescript -instance functorMaybe :: Functor Maybe -instance applyMaybe :: Apply Maybe -instance applicativeMaybe :: Applicative Maybe -instance altMaybe :: Alt Maybe -instance plusMaybe :: Plus Maybe -instance alternativeMaybe :: Alternative Maybe -instance bindMaybe :: Bind Maybe -instance monadMaybe :: Monad Maybe -instance monadPlusMaybe :: MonadPlus Maybe -instance extendMaybe :: Extend Maybe -instance invariantMaybe :: Invariant Maybe -instance semigroupMaybe :: (Semigroup a) => Semigroup (Maybe a) -instance monoidMaybe :: (Semigroup a) => Monoid (Maybe a) -instance semiringMaybe :: (Semiring a) => Semiring (Maybe a) -instance moduloSemiringMaybe :: (ModuloSemiring a) => ModuloSemiring (Maybe a) -instance ringMaybe :: (Ring a) => Ring (Maybe a) -instance divisionRingMaybe :: (DivisionRing a) => DivisionRing (Maybe a) -instance numMaybe :: (Num a) => Num (Maybe a) -instance eqMaybe :: (Eq a) => Eq (Maybe a) -instance ordMaybe :: (Ord a) => Ord (Maybe a) -instance boundedMaybe :: (Bounded a) => Bounded (Maybe a) -instance boundedOrdMaybe :: (BoundedOrd a) => BoundedOrd (Maybe a) -instance booleanAlgebraMaybe :: (BooleanAlgebra a) => BooleanAlgebra (Maybe a) -instance showMaybe :: (Show a) => Show (Maybe a) -``` - -#### `maybe` - -``` purescript -maybe :: forall a b. b -> (a -> b) -> Maybe a -> b -``` - -Takes a default value, a function, and a `Maybe` value. If the `Maybe` -value is `Nothing` the default value is returned, otherwise the function -is applied to the value inside the `Just` and the result is returned. - -``` purescript -maybe x f Nothing == x -maybe x f (Just y) == f y -``` - -#### `maybe'` - -``` purescript -maybe' :: forall a b. (Unit -> b) -> (a -> b) -> Maybe a -> b -``` - -Similar to `maybe` but for use in cases where the default value may be -expensive to compute. As PureScript is not lazy, the standard `maybe` has -to evaluate the default value before returning the result, whereas here -the value is only computed when the `Maybe` is known to be `Nothing`. - -``` purescript -maybe' (\_ -> x) f Nothing == x -maybe' (\_ -> x) f (Just y) == f y -``` - -#### `fromMaybe` - -``` purescript -fromMaybe :: forall a. a -> Maybe a -> a -``` - -Takes a default value, and a `Maybe` value. If the `Maybe` value is -`Nothing` the default value is returned, otherwise the value inside the -`Just` is returned. - -``` purescript -fromMaybe x Nothing == x -fromMaybe x (Just y) == y -``` - -#### `fromMaybe'` - -``` purescript -fromMaybe' :: forall a. (Unit -> a) -> Maybe a -> a -``` - -Similar to `fromMaybe` but for use in cases where the default value may be -expensive to compute. As PureScript is not lazy, the standard `fromMaybe` -has to evaluate the default value before returning the result, whereas here -the value is only computed when the `Maybe` is known to be `Nothing`. - -``` purescript -fromMaybe' (\_ -> x) Nothing == x -fromMaybe' (\_ -> x) (Just y) == y -``` - -#### `isJust` - -``` purescript -isJust :: forall a. Maybe a -> Boolean -``` - -Returns `true` when the `Maybe` value was constructed with `Just`. - -#### `isNothing` - -``` purescript -isNothing :: forall a. Maybe a -> Boolean -``` - -Returns `true` when the `Maybe` value is `Nothing`. - - diff --git a/docs/Data/Maybe/First.md b/docs/Data/Maybe/First.md deleted file mode 100644 index 295fc82..0000000 --- a/docs/Data/Maybe/First.md +++ /dev/null @@ -1,42 +0,0 @@ -## Module Data.Maybe.First - -#### `First` - -``` purescript -newtype First a - = First (Maybe a) -``` - -Monoid returning the first (left-most) non-`Nothing` value. - -``` purescript -First (Just x) <> First (Just y) == First (Just x) -First Nothing <> First (Just y) == First (Just y) -First Nothing <> Nothing == First Nothing -mempty :: First _ == First Nothing -``` - -##### Instances -``` purescript -instance eqFirst :: (Eq a) => Eq (First a) -instance ordFirst :: (Ord a) => Ord (First a) -instance boundedFirst :: (Bounded a) => Bounded (First a) -instance functorFirst :: Functor First -instance applyFirst :: Apply First -instance applicativeFirst :: Applicative First -instance bindFirst :: Bind First -instance monadFirst :: Monad First -instance extendFirst :: Extend First -instance invariantFirst :: Invariant First -instance showFirst :: (Show a) => Show (First a) -instance semigroupFirst :: Semigroup (First a) -instance monoidFirst :: Monoid (First a) -``` - -#### `runFirst` - -``` purescript -runFirst :: forall a. First a -> Maybe a -``` - - diff --git a/docs/Data/Maybe/Last.md b/docs/Data/Maybe/Last.md deleted file mode 100644 index 0157e1f..0000000 --- a/docs/Data/Maybe/Last.md +++ /dev/null @@ -1,42 +0,0 @@ -## Module Data.Maybe.Last - -#### `Last` - -``` purescript -newtype Last a - = Last (Maybe a) -``` - -Monoid returning the last (right-most) non-`Nothing` value. - -``` purescript -Last (Just x) <> Last (Just y) == Last (Just y) -Last (Just x) <> Nothing == Last (Just x) -Last Nothing <> Nothing == Last Nothing -mempty :: Last _ == Last Nothing -``` - -##### Instances -``` purescript -instance eqLast :: (Eq a) => Eq (Last a) -instance ordLast :: (Ord a) => Ord (Last a) -instance boundedLast :: (Bounded a) => Bounded (Last a) -instance functorLast :: Functor Last -instance applyLast :: Apply Last -instance applicativeLast :: Applicative Last -instance bindLast :: Bind Last -instance monadLast :: Monad Last -instance extendLast :: Extend Last -instance invariantLast :: Invariant Last -instance showLast :: (Show a) => Show (Last a) -instance semigroupLast :: Semigroup (Last a) -instance monoidLast :: Monoid (Last a) -``` - -#### `runLast` - -``` purescript -runLast :: forall a. Last a -> Maybe a -``` - - diff --git a/docs/Data/Maybe/Unsafe.md b/docs/Data/Maybe/Unsafe.md deleted file mode 100644 index c1504c5..0000000 --- a/docs/Data/Maybe/Unsafe.md +++ /dev/null @@ -1,13 +0,0 @@ -## Module Data.Maybe.Unsafe - -#### `fromJust` - -``` purescript -fromJust :: forall a. Maybe a -> a -``` - -A partial function that extracts the value from the `Just` data -constructor. Passing `Nothing` to `fromJust` will throw an error at -runtime. - - diff --git a/package.json b/package.json index 2a80565..f7e0e40 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,11 @@ { "private": true, "scripts": { - "postinstall": "pulp dep install", - "build": "pulp build && rimraf docs && pulp docs" + "clean": "rimraf output && rimraf .pulp-cache", + "build": "pulp build" }, "devDependencies": { - "pulp": "^4.0.1", - "rimraf": "^2.4.1" + "pulp": "^8.1.0", + "rimraf": "^2.5.0" } } diff --git a/src/Data/Maybe.purs b/src/Data/Maybe.purs index 05b1d48..a8967b6 100644 --- a/src/Data/Maybe.purs +++ b/src/Data/Maybe.purs @@ -1,75 +1,33 @@ module Data.Maybe where -import Prelude - -import Control.Alt (Alt) -import Control.Alternative (Alternative) -import Control.Extend (Extend) -import Control.MonadPlus (MonadPlus) -import Control.Plus (Plus) -import Data.Functor.Invariant (Invariant, imapF) -import Data.Monoid (Monoid) +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.BooleanAlgebra (class BooleanAlgebra, conj, disj, not) +import Data.Bounded (class Bounded, top) +import Data.BoundedOrd (class BoundedOrd) +import Data.Eq (class Eq, (==)) +import Data.Function (const, id) +import Data.Functor (class Functor, map, (<$>)) +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` -- | is the non-null value `x`. -data Maybe a = Nothing | Just a - --- | Takes a default value, a function, and a `Maybe` value. If the `Maybe` --- | value is `Nothing` the default value is returned, otherwise the function --- | is applied to the value inside the `Just` and the result is returned. --- | --- | ``` purescript --- | maybe x f Nothing == x --- | maybe x f (Just y) == f y --- | ``` -maybe :: forall a b. b -> (a -> b) -> Maybe a -> b -maybe b _ Nothing = b -maybe _ f (Just a) = f a - --- | Similar to `maybe` but for use in cases where the default value may be --- | expensive to compute. As PureScript is not lazy, the standard `maybe` has --- | to evaluate the default value before returning the result, whereas here --- | the value is only computed when the `Maybe` is known to be `Nothing`. --- | --- | ``` purescript --- | maybe' (\_ -> x) f Nothing == x --- | maybe' (\_ -> x) f (Just y) == f y --- | ``` -maybe' :: forall a b. (Unit -> b) -> (a -> b) -> Maybe a -> b -maybe' g _ Nothing = g unit -maybe' _ f (Just a) = f a - --- | Takes a default value, and a `Maybe` value. If the `Maybe` value is --- | `Nothing` the default value is returned, otherwise the value inside the --- | `Just` is returned. --- | --- | ``` purescript --- | fromMaybe x Nothing == x --- | fromMaybe x (Just y) == y --- | ``` -fromMaybe :: forall a. a -> Maybe a -> a -fromMaybe a = maybe a id - --- | Similar to `fromMaybe` but for use in cases where the default value may be --- | expensive to compute. As PureScript is not lazy, the standard `fromMaybe` --- | has to evaluate the default value before returning the result, whereas here --- | the value is only computed when the `Maybe` is known to be `Nothing`. --- | --- | ``` purescript --- | fromMaybe' (\_ -> x) Nothing == x --- | fromMaybe' (\_ -> x) (Just y) == y --- | ``` -fromMaybe' :: forall a. (Unit -> a) -> Maybe a -> a -fromMaybe' a = maybe' a id - --- | Returns `true` when the `Maybe` value was constructed with `Just`. -isJust :: forall a. Maybe a -> Boolean -isJust = maybe false (const true) - --- | Returns `true` when the `Maybe` value is `Nothing`. -isNothing :: forall a. Maybe a -> Boolean -isNothing = maybe true (const false) +data Maybe a = Just a | Nothing -- | The `Functor` instance allows functions to transform the contents of a -- | `Just` with the `<$>` operator: @@ -198,9 +156,7 @@ instance bindMaybe :: Bind Maybe where -- | ``` instance monadMaybe :: Monad Maybe --- | The `MonadPlus` instance guarantees that there are both `Monad` and --- | `Alternative` instances for `Maybe`. -instance monadPlusMaybe :: MonadPlus Maybe +instance monadZeroMaybe :: MonadZero Maybe -- | The `Extend` instance allows sequencing of `Maybe` values and functions -- | that accept a `Maybe a` and return a non-`Maybe` result using the @@ -228,35 +184,18 @@ instance invariantMaybe :: Invariant Maybe where -- | Nothing <> Just y = Just y -- | Nothing <> Nothing = Nothing -- | ``` -instance semigroupMaybe :: (Semigroup a) => Semigroup (Maybe a) where +instance semigroupMaybe :: Semigroup a => Semigroup (Maybe a) where append Nothing y = y append x Nothing = x append (Just x) (Just y) = Just (x <> y) -instance monoidMaybe :: (Semigroup a) => Monoid (Maybe a) where +instance monoidMaybe :: Semigroup a => Monoid (Maybe a) where mempty = Nothing -instance semiringMaybe :: (Semiring a) => Semiring (Maybe a) where - add x y = add <$> x <*> y - one = Just one - mul x y = mul <$> x <*> y - zero = Just zero - -instance moduloSemiringMaybe :: (ModuloSemiring a) => ModuloSemiring (Maybe a) where - mod x y = mod <$> x <*> y - div x y = div <$> x <*> y - -instance ringMaybe :: (Ring a) => Ring (Maybe a) where - sub x y = sub <$> x <*> y - -instance divisionRingMaybe :: (DivisionRing a) => DivisionRing (Maybe a) - -instance numMaybe :: (Num a) => Num (Maybe a) - -- | 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 +instance eqMaybe :: Eq a => Eq (Maybe a) where eq Nothing Nothing = true eq (Just a1) (Just a2) = a1 == a2 eq _ _ = false @@ -266,19 +205,19 @@ instance eqMaybe :: (Eq a) => Eq (Maybe a) where -- | the type the `Maybe` contains. -- | -- | `Nothing` is considered to be less than any `Just` value. -instance ordMaybe :: (Ord a) => Ord (Maybe a) where +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 -instance boundedMaybe :: (Bounded a) => Bounded (Maybe a) where +instance boundedMaybe :: Bounded a => Bounded (Maybe a) where top = Just top bottom = Nothing -instance boundedOrdMaybe :: (BoundedOrd a) => BoundedOrd (Maybe a) +instance boundedOrdMaybe :: BoundedOrd a => BoundedOrd (Maybe a) -instance booleanAlgebraMaybe :: (BooleanAlgebra a) => BooleanAlgebra (Maybe a) where +instance booleanAlgebraMaybe :: BooleanAlgebra a => BooleanAlgebra (Maybe a) where conj x y = conj <$> x <*> y disj x y = disj <$> x <*> y not = map not @@ -286,6 +225,68 @@ instance booleanAlgebraMaybe :: (BooleanAlgebra a) => BooleanAlgebra (Maybe a) w -- | The `Show` instance allows `Maybe` values to be rendered as a string with -- | `show` whenever there is an `Show` instance for the type the `Maybe` -- | contains. -instance showMaybe :: (Show a) => Show (Maybe a) where - show (Just x) = "Just (" ++ show x ++ ")" +instance showMaybe :: Show a => Show (Maybe a) where + show (Just x) = "(Just " <> show x <> ")" show Nothing = "Nothing" + +-- | Takes a default value, a function, and a `Maybe` value. If the `Maybe` +-- | value is `Nothing` the default value is returned, otherwise the function +-- | is applied to the value inside the `Just` and the result is returned. +-- | +-- | ``` purescript +-- | maybe x f Nothing == x +-- | maybe x f (Just y) == f y +-- | ``` +maybe :: forall a b. b -> (a -> b) -> Maybe a -> b +maybe b _ Nothing = b +maybe _ f (Just a) = f a + +-- | Similar to `maybe` but for use in cases where the default value may be +-- | expensive to compute. As PureScript is not lazy, the standard `maybe` has +-- | to evaluate the default value before returning the result, whereas here +-- | the value is only computed when the `Maybe` is known to be `Nothing`. +-- | +-- | ``` purescript +-- | maybe' (\_ -> x) f Nothing == x +-- | maybe' (\_ -> x) f (Just y) == f y +-- | ``` +maybe' :: forall a b. (Unit -> b) -> (a -> b) -> Maybe a -> b +maybe' g _ Nothing = g unit +maybe' _ f (Just a) = f a + +-- | Takes a default value, and a `Maybe` value. If the `Maybe` value is +-- | `Nothing` the default value is returned, otherwise the value inside the +-- | `Just` is returned. +-- | +-- | ``` purescript +-- | fromMaybe x Nothing == x +-- | fromMaybe x (Just y) == y +-- | ``` +fromMaybe :: forall a. a -> Maybe a -> a +fromMaybe a = maybe a id + +-- | Similar to `fromMaybe` but for use in cases where the default value may be +-- | expensive to compute. As PureScript is not lazy, the standard `fromMaybe` +-- | has to evaluate the default value before returning the result, whereas here +-- | the value is only computed when the `Maybe` is known to be `Nothing`. +-- | +-- | ``` purescript +-- | fromMaybe' (\_ -> x) Nothing == x +-- | fromMaybe' (\_ -> x) (Just y) == y +-- | ``` +fromMaybe' :: forall a. (Unit -> a) -> Maybe a -> a +fromMaybe' a = maybe' a id + +-- | Returns `true` when the `Maybe` value was constructed with `Just`. +isJust :: forall a. Maybe a -> Boolean +isJust = maybe false (const true) + +-- | Returns `true` when the `Maybe` value is `Nothing`. +isNothing :: forall a. Maybe a -> Boolean +isNothing = maybe true (const false) + +-- | A partial function that extracts the value from the `Just` data +-- | constructor. Passing `Nothing` to `fromJust` will throw an error at +-- | runtime. +fromJust :: forall a. Partial => Maybe a -> a +fromJust (Just x) = x diff --git a/src/Data/Maybe/First.purs b/src/Data/Maybe/First.purs index 524ac7e..a01c91b 100644 --- a/src/Data/Maybe/First.purs +++ b/src/Data/Maybe/First.purs @@ -1,12 +1,22 @@ module Data.Maybe.First where -import Prelude - -import Control.Comonad (Comonad) -import Control.Extend (Extend, extend) -import Data.Functor.Invariant (Invariant, imapF) +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.BoundedOrd (class BoundedOrd) +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 (Monoid) +import Data.Monoid (class Monoid) +import Data.Ord (class Ord, compare) +import Data.Semigroup (class Semigroup, (<>)) +import Data.Show (class Show, show) -- | Monoid returning the first (left-most) non-`Nothing` value. -- | @@ -31,9 +41,14 @@ instance boundedFirst :: (Bounded a) => Bounded (First a) where top = First top bottom = First bottom +instance boundedOrdFirst :: BoundedOrd a => BoundedOrd (First a) where + instance functorFirst :: Functor First where map f (First x) = First (f <$> x) +instance invariantFirst :: Invariant First where + imap = imapF + instance applyFirst :: Apply First where apply (First f) (First x) = First (f <*> x) @@ -48,11 +63,8 @@ instance monadFirst :: Monad First instance extendFirst :: Extend First where extend f (First x) = First (extend (f <<< First) x) -instance invariantFirst :: Invariant First where - imap = imapF - instance showFirst :: (Show a) => Show (First a) where - show (First a) = "First (" ++ show a ++ ")" + show (First a) = "First (" <> show a <> ")" instance semigroupFirst :: Semigroup (First a) where append first@(First (Just _)) _ = first diff --git a/src/Data/Maybe/Last.purs b/src/Data/Maybe/Last.purs index 8d03c99..f269533 100644 --- a/src/Data/Maybe/Last.purs +++ b/src/Data/Maybe/Last.purs @@ -1,12 +1,22 @@ module Data.Maybe.Last where -import Prelude - -import Control.Comonad (Comonad) -import Control.Extend (Extend, extend) -import Data.Functor.Invariant (Invariant, imapF) +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.BoundedOrd (class BoundedOrd) +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 (Monoid) +import Data.Monoid (class Monoid) +import Data.Ord (class Ord, compare) +import Data.Semigroup (class Semigroup, (<>)) +import Data.Show (class Show, show) -- | Monoid returning the last (right-most) non-`Nothing` value. -- | @@ -21,19 +31,24 @@ newtype Last a = Last (Maybe a) runLast :: forall a. Last a -> Maybe a runLast (Last m) = m -instance eqLast :: (Eq a) => Eq (Last a) where +instance eqLast :: Eq a => Eq (Last a) where eq (Last x) (Last y) = x == y -instance ordLast :: (Ord a) => Ord (Last a) where +instance ordLast :: Ord a => Ord (Last a) where compare (Last x) (Last y) = compare x y -instance boundedLast :: (Bounded a) => Bounded (Last a) where +instance boundedLast :: Bounded a => Bounded (Last a) where top = Last top bottom = Last bottom +instance boundedOrdLast :: BoundedOrd a => BoundedOrd (Last a) where + instance functorLast :: Functor Last where map f (Last x) = Last (f <$> x) +instance invariantLast :: Invariant Last where + imap = imapF + instance applyLast :: Apply Last where apply (Last f) (Last x) = Last (f <*> x) @@ -48,11 +63,8 @@ instance monadLast :: Monad Last instance extendLast :: Extend Last where extend f (Last x) = Last (extend (f <<< Last) x) -instance invariantLast :: Invariant Last where - imap = imapF - -instance showLast :: (Show a) => Show (Last a) where - show (Last a) = "Last (" ++ show a ++ ")" +instance showLast :: Show a => Show (Last a) where + show (Last a) = "(Last " <> show a <> ")" instance semigroupLast :: Semigroup (Last a) where append _ last@(Last (Just _)) = last diff --git a/src/Data/Maybe/Unsafe.js b/src/Data/Maybe/Unsafe.js deleted file mode 100644 index 50b3a0e..0000000 --- a/src/Data/Maybe/Unsafe.js +++ /dev/null @@ -1,8 +0,0 @@ -/* global exports */ -"use strict"; - -// module Data.Maybe.Unsafe - -exports.unsafeThrow = function (msg) { - throw new Error(msg); -}; diff --git a/src/Data/Maybe/Unsafe.purs b/src/Data/Maybe/Unsafe.purs deleted file mode 100644 index d9ddd08..0000000 --- a/src/Data/Maybe/Unsafe.purs +++ /dev/null @@ -1,14 +0,0 @@ -module Data.Maybe.Unsafe where - -import Prelude - -import Data.Maybe - --- | A partial function that extracts the value from the `Just` data --- | constructor. Passing `Nothing` to `fromJust` will throw an error at --- | runtime. -fromJust :: forall a. Maybe a -> a -fromJust (Just x) = x -fromJust Nothing = unsafeThrow "Data.Maybe.Unsafe.fromJust called on Nothing" - -foreign import unsafeThrow :: forall a. String -> a