@@ -5,8 +5,6 @@ module Data.NonEmpty
5
5
, singleton
6
6
, (:|)
7
7
, foldl1
8
- , foldMap1
9
- , fold1
10
8
, fromNonEmpty
11
9
, oneOf
12
10
, head
@@ -18,13 +16,13 @@ import Prelude
18
16
import Control.Alt ((<|>))
19
17
import Control.Alternative (class Alternative )
20
18
import Control.Plus (class Plus , empty )
21
- import Data.Eq (class Eq1 , eq1 )
19
+ import Data.Eq (class Eq1 )
22
20
import Data.Foldable (class Foldable , foldl , foldr , foldMap )
23
21
import Data.FoldableWithIndex (class FoldableWithIndex , foldMapWithIndex , foldlWithIndex , foldrWithIndex )
24
22
import Data.FunctorWithIndex (class FunctorWithIndex , mapWithIndex )
25
23
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 )
28
26
import Data.Traversable (class Traversable , traverse , sequence )
29
27
import Data.TraversableWithIndex (class TraversableWithIndex , traverseWithIndex )
30
28
@@ -49,14 +47,6 @@ singleton a = a :| empty
49
47
foldl1 :: forall f a . Foldable f => (a -> a -> a ) -> NonEmpty f a -> a
50
48
foldl1 f (a :| fa) = foldl f a fa
51
49
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
-
60
50
fromNonEmpty :: forall f a r . (a -> f a -> r ) -> NonEmpty f a -> r
61
51
fromNonEmpty f (a :| fa) = a `f` fa
62
52
@@ -74,23 +64,15 @@ tail (_ :| xs) = xs
74
64
instance showNonEmpty :: (Show a , Show (f a )) => Show (NonEmpty f a ) where
75
65
show (a :| fa) = " (NonEmpty " <> show a <> " " <> show fa <> " )"
76
66
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 )
79
68
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 )
82
70
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 )
85
72
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 )
91
74
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 )
94
76
95
77
instance functorWithIndex
96
78
:: FunctorWithIndex i f
@@ -119,6 +101,6 @@ instance traversableWithIndexNonEmpty
119
101
traverseWithIndex f (a :| fa) =
120
102
NonEmpty <$> f Nothing a <*> traverseWithIndex (f <<< Just ) fa
121
103
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
124
106
foldMap1 f (a :| fa) = foldl (\s a1 -> s <> f a1) (f a) fa
0 commit comments