Skip to content

Commit 9577d11

Browse files
rhendricpaluh
authored andcommitted
fixup! Fix Foldable1 (NonEmpty f) instance
1 parent 18342e4 commit 9577d11

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/Data/NonEmpty.purs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ module Data.NonEmpty
44
( NonEmpty(..)
55
, singleton
66
, (:|)
7+
, foldl1
78
, fromNonEmpty
89
, oneOf
910
, head
1011
, tail
11-
, module Exports
1212
) where
1313

1414
import Prelude
@@ -23,7 +23,6 @@ import Data.FunctorWithIndex (class FunctorWithIndex, mapWithIndex)
2323
import Data.Maybe (Maybe(..), maybe)
2424
import Data.Ord (class Ord1)
2525
import Data.Semigroup.Foldable (class Foldable1, foldMap1)
26-
import Data.Semigroup.Foldable (foldl1) as Exports
2726
import Data.Traversable (class Traversable, traverse, sequence)
2827
import Data.TraversableWithIndex (class TraversableWithIndex, traverseWithIndex)
2928
import Data.Tuple (uncurry)
@@ -47,6 +46,10 @@ infixr 5 NonEmpty as :|
4746
singleton :: forall f a. Plus f => a -> NonEmpty f a
4847
singleton a = a :| empty
4948

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+
5053
fromNonEmpty :: forall f a r. (a -> f a -> r) -> NonEmpty f a -> r
5154
fromNonEmpty f (a :| fa) = a `f` fa
5255

@@ -105,7 +108,7 @@ instance foldable1NonEmpty :: Foldable f => Foldable1 (NonEmpty f) where
105108
fold1 = foldMap1 identity
106109
foldMap1 f (a :| fa) = foldl (\s a1 -> s <> f a1) (f a) fa
107110
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
109112

110113
instance unfoldable1NonEmpty :: Unfoldable f => Unfoldable1 (NonEmpty f) where
111114
unfoldr1 f b = uncurry (:|) $ unfoldr (map f) <$> f b

0 commit comments

Comments
 (0)