@@ -5,12 +5,11 @@ module Data.NonEmpty
5
5
, singleton
6
6
, (:|)
7
7
, foldl1
8
- , foldMap1
9
- , fold1
10
8
, fromNonEmpty
11
9
, oneOf
12
10
, head
13
11
, tail
12
+ , module Data.Semigroup.Foldable
14
13
) where
15
14
16
15
import Prelude
@@ -24,6 +23,7 @@ import Data.FoldableWithIndex (class FoldableWithIndex, foldMapWithIndex, foldlW
24
23
import Data.FunctorWithIndex (class FunctorWithIndex , mapWithIndex )
25
24
import Data.Maybe (Maybe (..))
26
25
import Data.Ord (class Ord1 , compare1 )
26
+ import Data.Semigroup.Foldable (fold1 , foldMap1 )
27
27
import Data.Traversable (class Traversable , traverse , sequence )
28
28
import Data.TraversableWithIndex (class TraversableWithIndex , traverseWithIndex )
29
29
@@ -48,14 +48,6 @@ singleton a = a :| empty
48
48
foldl1 :: forall f a . Foldable f => (a -> a -> a ) -> NonEmpty f a -> a
49
49
foldl1 f (a :| fa) = foldl f a fa
50
50
51
- -- | Fold a non-empty structure, collecting results in a `Semigroup`.
52
- foldMap1 :: forall f a s . Semigroup s => Foldable f => (a -> s ) -> NonEmpty f a -> s
53
- foldMap1 f (a :| fa) = foldl (\s a1 -> s <> f a1) (f a) fa
54
-
55
- -- | Fold a non-empty structure.
56
- fold1 :: forall f s . Semigroup s => Foldable f => NonEmpty f s -> s
57
- fold1 = foldMap1 id
58
-
59
51
fromNonEmpty :: forall f a r . (a -> f a -> r ) -> NonEmpty f a -> r
60
52
fromNonEmpty f (a :| fa) = a `f` fa
61
53
@@ -117,3 +109,7 @@ instance traversableWithIndexNonEmpty
117
109
=> TraversableWithIndex (Maybe i ) (NonEmpty f ) where
118
110
traverseWithIndex f (a :| fa) =
119
111
NonEmpty <$> f Nothing a <*> traverseWithIndex (f <<< Just ) fa
112
+
113
+ instance foldable1NonEmpty :: Foldable f => SF.Foldable1 (NonEmpty f ) where
114
+ fold1 = foldMap1 id
115
+ foldMap1 f (a :| fa) = foldl (\s a1 -> s <> f a1) (f a) fa
0 commit comments