Skip to content

Commit 5be916a

Browse files
committed
Updates for 0.12
1 parent 1d53fbd commit 5be916a

File tree

3 files changed

+18
-36
lines changed

3 files changed

+18
-36
lines changed

bower.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@
1717
"package.json"
1818
],
1919
"dependencies": {
20-
"purescript-foldable-traversable": "^3.4.0",
21-
"purescript-prelude": "^3.0.0"
20+
"purescript-foldable-traversable": "#compiler/0.12"
2221
},
2322
"devDependencies": {
24-
"purescript-assert": "^3.0.0",
25-
"purescript-console": "^3.0.0"
23+
"purescript-assert": "#compiler/0.12",
24+
"purescript-console": "#compiler/0.12"
2625
}
2726
}

src/Data/NonEmpty.purs

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ module Data.NonEmpty
55
, singleton
66
, (:|)
77
, foldl1
8-
, foldMap1
9-
, fold1
108
, fromNonEmpty
119
, oneOf
1210
, head
@@ -18,13 +16,13 @@ import Prelude
1816
import Control.Alt ((<|>))
1917
import Control.Alternative (class Alternative)
2018
import Control.Plus (class Plus, empty)
21-
import Data.Eq (class Eq1, eq1)
19+
import Data.Eq (class Eq1)
2220
import Data.Foldable (class Foldable, foldl, foldr, foldMap)
2321
import Data.FoldableWithIndex (class FoldableWithIndex, foldMapWithIndex, foldlWithIndex, foldrWithIndex)
2422
import Data.FunctorWithIndex (class FunctorWithIndex, mapWithIndex)
2523
import Data.Maybe (Maybe(..))
26-
import Data.Ord (class Ord1, compare1)
27-
import Data.Semigroup.Foldable as F1
24+
import Data.Ord (class Ord1)
25+
import Data.Semigroup.Foldable (class Foldable1, foldMap1)
2826
import Data.Traversable (class Traversable, traverse, sequence)
2927
import Data.TraversableWithIndex (class TraversableWithIndex, traverseWithIndex)
3028

@@ -49,14 +47,6 @@ singleton a = a :| empty
4947
foldl1 :: forall f a. Foldable f => (a -> a -> a) -> NonEmpty f a -> a
5048
foldl1 f (a :| fa) = foldl f a fa
5149

52-
-- | Fold a non-empty structure, collecting results in a `Semigroup`.
53-
foldMap1 :: forall f a s. Semigroup s => Foldable f => (a -> s) -> NonEmpty f a -> s
54-
foldMap1 = F1.foldMap1
55-
56-
-- | Fold a non-empty structure.
57-
fold1 :: forall f s. Semigroup s => Foldable f => NonEmpty f s -> s
58-
fold1 = F1.fold1
59-
6050
fromNonEmpty :: forall f a r. (a -> f a -> r) -> NonEmpty f a -> r
6151
fromNonEmpty f (a :| fa) = a `f` fa
6252

@@ -74,23 +64,15 @@ tail (_ :| xs) = xs
7464
instance showNonEmpty :: (Show a, Show (f a)) => Show (NonEmpty f a) where
7565
show (a :| fa) = "(NonEmpty " <> show a <> " " <> show fa <> ")"
7666

77-
instance eqNonEmpty :: (Eq1 f, Eq a) => Eq (NonEmpty f a) where
78-
eq = eq1
67+
derive instance eqNonEmpty :: (Eq1 f, Eq a) => Eq (NonEmpty f a)
7968

80-
instance eq1NonEmpty :: Eq1 f => Eq1 (NonEmpty f) where
81-
eq1 (NonEmpty a fa) (NonEmpty b fb) = a == b && fa `eq1` fb
69+
derive instance eq1NonEmpty :: Eq1 f => Eq1 (NonEmpty f)
8270

83-
instance ordNonEmpty :: (Ord1 f, Ord a) => Ord (NonEmpty f a) where
84-
compare = compare1
71+
derive instance ordNonEmpty :: (Ord1 f, Ord a) => Ord (NonEmpty f a)
8572

86-
instance ord1NonEmpty :: Ord1 f => Ord1 (NonEmpty f) where
87-
compare1 (NonEmpty a fa) (NonEmpty b fb) =
88-
case compare a b of
89-
EQ -> compare1 fa fb
90-
c -> c
73+
derive instance ord1NonEmpty :: Ord1 f => Ord1 (NonEmpty f)
9174

92-
instance functorNonEmpty :: Functor f => Functor (NonEmpty f) where
93-
map f (a :| fa) = f a :| map f fa
75+
derive instance functorNonEmpty :: Functor f => Functor (NonEmpty f)
9476

9577
instance functorWithIndex
9678
:: FunctorWithIndex i f
@@ -119,6 +101,6 @@ instance traversableWithIndexNonEmpty
119101
traverseWithIndex f (a :| fa) =
120102
NonEmpty <$> f Nothing a <*> traverseWithIndex (f <<< Just) fa
121103

122-
instance foldable1NonEmpty :: Foldable f => F1.Foldable1 (NonEmpty f) where
123-
fold1 = foldMap1 id
104+
instance foldable1NonEmpty :: Foldable f => Foldable1 (NonEmpty f) where
105+
fold1 = foldMap1 identity
124106
foldMap1 f (a :| fa) = foldl (\s a1 -> s <> f a1) (f a) fa

test/Main.purs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@ module Test.Main where
22

33
import Prelude
44

5-
import Control.Monad.Eff (Eff)
65
import Data.Foldable (fold, foldl)
76
import Data.Maybe (Maybe(..))
8-
import Data.NonEmpty (NonEmpty(), (:|), fold1, foldl1, oneOf, head, tail, singleton)
9-
import Test.Assert (ASSERT, assert)
7+
import Data.NonEmpty (NonEmpty, (:|), foldl1, oneOf, head, tail, singleton)
8+
import Data.Semigroup.Foldable (fold1)
9+
import Effect (Effect)
10+
import Test.Assert (assert)
1011

1112
type AtLeastTwo f a = NonEmpty (NonEmpty f) a
1213

1314
second :: forall f a. AtLeastTwo f a -> a
1415
second = tail >>> head
1516

16-
main :: Eff (assert :: ASSERT) Unit
17+
main :: Effect Unit
1718
main = do
1819
assert $ singleton 0 == 0 :| []
1920
assert $ 0 :| Nothing /= 0 :| Just 1

0 commit comments

Comments
 (0)