diff --git a/LICENSE b/LICENSE index 04d7a8c..311379c 100644 --- a/LICENSE +++ b/LICENSE @@ -1,20 +1,26 @@ -The MIT License (MIT) +Copyright 2018 PureScript -Copyright (c) 2016 Phil Freeman +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software is furnished to do so, -subject to the following conditions: +1. Redistributions of source code must retain the above copyright notice, this +list of conditions and the following disclaimer. -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. +2. Redistributions in binary form must reproduce the above copyright notice, +this list of conditions and the following disclaimer in the documentation and/or +other materials provided with the distribution. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +3. Neither the name of the copyright holder nor the names of its contributors +may be used to endorse or promote products derived from this software without +specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/bower.json b/bower.json index 47236ed..abf3504 100644 --- a/bower.json +++ b/bower.json @@ -1,8 +1,7 @@ { "name": "purescript-nonempty", "homepage": "https://github.com/purescript/purescript-nonempty", - "description": "A generic non-empty data structure", - "license": "MIT", + "license": "BSD-3-Clause", "repository": { "type": "git", "url": "git://github.com/purescript/purescript-nonempty.git" @@ -17,12 +16,15 @@ "package.json" ], "dependencies": { - "purescript-foldable-traversable": "^3.4.0", - "purescript-prelude": "^3.0.0", - "purescript-unfoldable": "^3.2.0" + "purescript-control": "^4.0.0", + "purescript-foldable-traversable": "^4.0.0", + "purescript-maybe": "^4.0.0", + "purescript-prelude": "^4.0.0", + "purescript-tuples": "^5.0.0", + "purescript-unfoldable": "^4.0.0" }, "devDependencies": { - "purescript-assert": "^3.0.0", - "purescript-console": "^3.0.0" + "purescript-assert": "^4.0.0", + "purescript-console": "^4.0.0" } } diff --git a/package.json b/package.json index bf77170..5a4bff0 100644 --- a/package.json +++ b/package.json @@ -6,8 +6,8 @@ "test": "pulp test" }, "devDependencies": { - "pulp": "^10.0.4", - "purescript-psa": "^0.5.0-rc.1", - "rimraf": "^2.6.1" + "pulp": "^12.2.0", + "purescript-psa": "^0.6.0", + "rimraf": "^2.6.2" } } diff --git a/src/Data/NonEmpty.purs b/src/Data/NonEmpty.purs index 8999067..957b88c 100644 --- a/src/Data/NonEmpty.purs +++ b/src/Data/NonEmpty.purs @@ -5,8 +5,6 @@ module Data.NonEmpty , singleton , (:|) , foldl1 - , foldMap1 - , fold1 , fromNonEmpty , oneOf , head @@ -18,13 +16,13 @@ import Prelude import Control.Alt ((<|>)) import Control.Alternative (class Alternative) import Control.Plus (class Plus, empty) -import Data.Eq (class Eq1, eq1) +import Data.Eq (class Eq1) import Data.Foldable (class Foldable, foldl, foldr, foldMap) import Data.FoldableWithIndex (class FoldableWithIndex, foldMapWithIndex, foldlWithIndex, foldrWithIndex) import Data.FunctorWithIndex (class FunctorWithIndex, mapWithIndex) import Data.Maybe (Maybe(..)) -import Data.Ord (class Ord1, compare1) -import Data.Semigroup.Foldable as F1 +import Data.Ord (class Ord1) +import Data.Semigroup.Foldable (class Foldable1, foldMap1) import Data.Traversable (class Traversable, traverse, sequence) import Data.TraversableWithIndex (class TraversableWithIndex, traverseWithIndex) import Data.Tuple (uncurry) @@ -52,14 +50,6 @@ singleton a = a :| empty foldl1 :: forall f a. Foldable f => (a -> a -> a) -> NonEmpty f a -> a foldl1 f (a :| fa) = foldl f a fa --- | Fold a non-empty structure, collecting results in a `Semigroup`. -foldMap1 :: forall f a s. Semigroup s => Foldable f => (a -> s) -> NonEmpty f a -> s -foldMap1 = F1.foldMap1 - --- | Fold a non-empty structure. -fold1 :: forall f s. Semigroup s => Foldable f => NonEmpty f s -> s -fold1 = F1.fold1 - fromNonEmpty :: forall f a r. (a -> f a -> r) -> NonEmpty f a -> r fromNonEmpty f (a :| fa) = a `f` fa @@ -77,23 +67,15 @@ tail (_ :| xs) = xs instance showNonEmpty :: (Show a, Show (f a)) => Show (NonEmpty f a) where show (a :| fa) = "(NonEmpty " <> show a <> " " <> show fa <> ")" -instance eqNonEmpty :: (Eq1 f, Eq a) => Eq (NonEmpty f a) where - eq = eq1 +derive instance eqNonEmpty :: (Eq1 f, Eq a) => Eq (NonEmpty f a) -instance eq1NonEmpty :: Eq1 f => Eq1 (NonEmpty f) where - eq1 (NonEmpty a fa) (NonEmpty b fb) = a == b && fa `eq1` fb +derive instance eq1NonEmpty :: Eq1 f => Eq1 (NonEmpty f) -instance ordNonEmpty :: (Ord1 f, Ord a) => Ord (NonEmpty f a) where - compare = compare1 +derive instance ordNonEmpty :: (Ord1 f, Ord a) => Ord (NonEmpty f a) -instance ord1NonEmpty :: Ord1 f => Ord1 (NonEmpty f) where - compare1 (NonEmpty a fa) (NonEmpty b fb) = - case compare a b of - EQ -> compare1 fa fb - c -> c +derive instance ord1NonEmpty :: Ord1 f => Ord1 (NonEmpty f) -instance functorNonEmpty :: Functor f => Functor (NonEmpty f) where - map f (a :| fa) = f a :| map f fa +derive instance functorNonEmpty :: Functor f => Functor (NonEmpty f) instance functorWithIndex :: FunctorWithIndex i f @@ -122,8 +104,8 @@ instance traversableWithIndexNonEmpty traverseWithIndex f (a :| fa) = NonEmpty <$> f Nothing a <*> traverseWithIndex (f <<< Just) fa -instance foldable1NonEmpty :: Foldable f => F1.Foldable1 (NonEmpty f) where - fold1 = foldMap1 id +instance foldable1NonEmpty :: Foldable f => Foldable1 (NonEmpty f) where + fold1 = foldMap1 identity foldMap1 f (a :| fa) = foldl (\s a1 -> s <> f a1) (f a) fa instance unfoldable1NonEmpty :: Unfoldable f => Unfoldable1 (NonEmpty f) where diff --git a/test/Main.purs b/test/Main.purs index 01df254..b0a7e9a 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -2,19 +2,20 @@ module Test.Main where import Prelude -import Control.Monad.Eff (Eff) import Data.Foldable (fold, foldl) import Data.Maybe (Maybe(..)) -import Data.NonEmpty (NonEmpty(), (:|), fold1, foldl1, oneOf, head, tail, singleton) +import Data.NonEmpty (NonEmpty, (:|), foldl1, oneOf, head, tail, singleton) +import Data.Semigroup.Foldable (fold1) import Data.Unfoldable1 as U1 -import Test.Assert (ASSERT, assert) +import Effect (Effect) +import Test.Assert (assert) type AtLeastTwo f a = NonEmpty (NonEmpty f) a second :: forall f a. AtLeastTwo f a -> a second = tail >>> head -main :: Eff (assert :: ASSERT) Unit +main :: Effect Unit main = do assert $ singleton 0 == 0 :| [] assert $ 0 :| Nothing /= 0 :| Just 1