@@ -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
import Data.Tuple (uncurry )
@@ -52,14 +50,6 @@ singleton a = a :| empty
52
50
foldl1 :: forall f a . Foldable f => (a -> a -> a ) -> NonEmpty f a -> a
53
51
foldl1 f (a :| fa) = foldl f a fa
54
52
55
- -- | Fold a non-empty structure, collecting results in a `Semigroup`.
56
- foldMap1 :: forall f a s . Semigroup s => Foldable f => (a -> s ) -> NonEmpty f a -> s
57
- foldMap1 = F1 .foldMap1
58
-
59
- -- | Fold a non-empty structure.
60
- fold1 :: forall f s . Semigroup s => Foldable f => NonEmpty f s -> s
61
- fold1 = F1 .fold1
62
-
63
53
fromNonEmpty :: forall f a r . (a -> f a -> r ) -> NonEmpty f a -> r
64
54
fromNonEmpty f (a :| fa) = a `f` fa
65
55
@@ -77,23 +67,15 @@ tail (_ :| xs) = xs
77
67
instance showNonEmpty :: (Show a , Show (f a )) => Show (NonEmpty f a ) where
78
68
show (a :| fa) = " (NonEmpty " <> show a <> " " <> show fa <> " )"
79
69
80
- instance eqNonEmpty :: (Eq1 f , Eq a ) => Eq (NonEmpty f a ) where
81
- eq = eq1
70
+ derive instance eqNonEmpty :: (Eq1 f , Eq a ) => Eq (NonEmpty f a )
82
71
83
- instance eq1NonEmpty :: Eq1 f => Eq1 (NonEmpty f ) where
84
- eq1 (NonEmpty a fa) (NonEmpty b fb) = a == b && fa `eq1` fb
72
+ derive instance eq1NonEmpty :: Eq1 f => Eq1 (NonEmpty f )
85
73
86
- instance ordNonEmpty :: (Ord1 f , Ord a ) => Ord (NonEmpty f a ) where
87
- compare = compare1
74
+ derive instance ordNonEmpty :: (Ord1 f , Ord a ) => Ord (NonEmpty f a )
88
75
89
- instance ord1NonEmpty :: Ord1 f => Ord1 (NonEmpty f ) where
90
- compare1 (NonEmpty a fa) (NonEmpty b fb) =
91
- case compare a b of
92
- EQ -> compare1 fa fb
93
- c -> c
76
+ derive instance ord1NonEmpty :: Ord1 f => Ord1 (NonEmpty f )
94
77
95
- instance functorNonEmpty :: Functor f => Functor (NonEmpty f ) where
96
- map f (a :| fa) = f a :| map f fa
78
+ derive instance functorNonEmpty :: Functor f => Functor (NonEmpty f )
97
79
98
80
instance functorWithIndex
99
81
:: FunctorWithIndex i f
@@ -122,8 +104,8 @@ instance traversableWithIndexNonEmpty
122
104
traverseWithIndex f (a :| fa) =
123
105
NonEmpty <$> f Nothing a <*> traverseWithIndex (f <<< Just ) fa
124
106
125
- instance foldable1NonEmpty :: Foldable f => F1. Foldable1 (NonEmpty f ) where
126
- fold1 = foldMap1 id
107
+ instance foldable1NonEmpty :: Foldable f => Foldable1 (NonEmpty f ) where
108
+ fold1 = foldMap1 identity
127
109
foldMap1 f (a :| fa) = foldl (\s a1 -> s <> f a1) (f a) fa
128
110
129
111
instance unfoldable1NonEmpty :: Unfoldable f => Unfoldable1 (NonEmpty f ) where
0 commit comments