@@ -4,11 +4,11 @@ module Data.NonEmpty
4
4
( NonEmpty (..)
5
5
, singleton
6
6
, (:|)
7
+ , foldl1
7
8
, fromNonEmpty
8
9
, oneOf
9
10
, head
10
11
, tail
11
- , module Exports
12
12
) where
13
13
14
14
import Prelude
@@ -23,7 +23,6 @@ import Data.FunctorWithIndex (class FunctorWithIndex, mapWithIndex)
23
23
import Data.Maybe (Maybe (..), maybe )
24
24
import Data.Ord (class Ord1 )
25
25
import Data.Semigroup.Foldable (class Foldable1 , foldMap1 )
26
- import Data.Semigroup.Foldable (foldl1 ) as Exports
27
26
import Data.Traversable (class Traversable , traverse , sequence )
28
27
import Data.TraversableWithIndex (class TraversableWithIndex , traverseWithIndex )
29
28
import Data.Tuple (uncurry )
@@ -47,6 +46,10 @@ infixr 5 NonEmpty as :|
47
46
singleton :: forall f a . Plus f => a -> NonEmpty f a
48
47
singleton a = a :| empty
49
48
49
+ -- | Fold a non-empty structure, collecting results using a binary operation.
50
+ foldl1 :: forall f a . Foldable f => (a -> a -> a ) -> NonEmpty f a -> a
51
+ foldl1 f (a :| fa) = foldl f a fa
52
+
50
53
fromNonEmpty :: forall f a r . (a -> f a -> r ) -> NonEmpty f a -> r
51
54
fromNonEmpty f (a :| fa) = a `f` fa
52
55
@@ -105,7 +108,7 @@ instance foldable1NonEmpty :: Foldable f => Foldable1 (NonEmpty f) where
105
108
fold1 = foldMap1 identity
106
109
foldMap1 f (a :| fa) = foldl (\s a1 -> s <> f a1) (f a) fa
107
110
foldr1 f (a :| fa) = maybe a (f a) $ foldr (\a1 -> Just <<< maybe a1 (f a1)) Nothing fa
108
- foldl1 f (a :| fa) = foldl f a fa
111
+ foldl1 = foldl1
109
112
110
113
instance unfoldable1NonEmpty :: Unfoldable f => Unfoldable1 (NonEmpty f ) where
111
114
unfoldr1 f b = uncurry (:|) $ unfoldr (map f) <$> f b
0 commit comments