diff --git a/.travis.yml b/.travis.yml index 28a61c0..c39bb0e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,8 @@ node_js: stable env: - PATH=$HOME/purescript:$PATH install: - - TAG=$(basename $(curl --location --silent --output /dev/null -w %{url_effective} https://github.com/purescript/purescript/releases/latest)) + # - TAG=$(basename $(curl --location --silent --output /dev/null -w %{url_effective} https://github.com/purescript/purescript/releases/latest)) + - TAG=v0.14.0-rc3 - curl --location --output $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 diff --git a/bower.json b/bower.json index abf3504..14e47cc 100644 --- a/bower.json +++ b/bower.json @@ -16,15 +16,15 @@ "package.json" ], "dependencies": { - "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" + "purescript-control": "master", + "purescript-foldable-traversable": "master", + "purescript-maybe": "master", + "purescript-prelude": "master", + "purescript-tuples": "master", + "purescript-unfoldable": "master" }, "devDependencies": { - "purescript-assert": "^4.0.0", - "purescript-console": "^4.0.0" + "purescript-assert": "master", + "purescript-console": "master" } } diff --git a/package.json b/package.json index d408361..1fac874 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ }, "devDependencies": { "pulp": "^15.0.0", - "purescript-psa": "^0.6.0", + "purescript-psa": "^0.8.0", "rimraf": "^2.6.2" } } diff --git a/src/Data/NonEmpty.purs b/src/Data/NonEmpty.purs index 957b88c..9e5f75a 100644 --- a/src/Data/NonEmpty.purs +++ b/src/Data/NonEmpty.purs @@ -20,7 +20,7 @@ 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.Maybe (Maybe(..), maybe) import Data.Ord (class Ord1) import Data.Semigroup.Foldable (class Foldable1, foldMap1) import Data.Traversable (class Traversable, traverse, sequence) @@ -107,6 +107,8 @@ instance traversableWithIndexNonEmpty instance foldable1NonEmpty :: Foldable f => Foldable1 (NonEmpty f) where fold1 = foldMap1 identity foldMap1 f (a :| fa) = foldl (\s a1 -> s <> f a1) (f a) fa + foldr1 f (a :| fa) = maybe a (f a) $ foldr (\a1 -> Just <<< maybe a1 (f a1)) Nothing fa + foldl1 = foldl1 instance unfoldable1NonEmpty :: Unfoldable f => Unfoldable1 (NonEmpty f) where unfoldr1 f b = uncurry (:|) $ unfoldr (map f) <$> f b diff --git a/test/Main.purs b/test/Main.purs index b0a7e9a..9e3fcac 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -5,7 +5,7 @@ import Prelude import Data.Foldable (fold, foldl) import Data.Maybe (Maybe(..)) import Data.NonEmpty (NonEmpty, (:|), foldl1, oneOf, head, tail, singleton) -import Data.Semigroup.Foldable (fold1) +import Data.Semigroup.Foldable (fold1, foldr1) import Data.Unfoldable1 as U1 import Effect (Effect) import Test.Assert (assert) @@ -19,7 +19,8 @@ main :: Effect Unit main = do assert $ singleton 0 == 0 :| [] assert $ 0 :| Nothing /= 0 :| Just 1 - assert $ foldl1 (+) (1 :| [2, 3]) == 6 + assert $ foldl1 (\l r -> "(" <> l <> r <> ")") ("a" :| ["b", "c", "d"]) == "(((ab)c)d)" + assert $ foldr1 (\l r -> "(" <> l <> r <> ")") ("a" :| ["b", "c", "d"]) == "(a(b(cd)))" assert $ foldl (+) 0 (1 :| [2, 3]) == 6 assert $ fold1 ("Hello" :| [" ", "World"]) == "Hello World" assert $ fold ("Hello" :| [" ", "World"]) == "Hello World"