summaryrefslogtreecommitdiff
path: root/libraries/base/Data/Foldable.hs
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/base/Data/Foldable.hs')
-rw-r--r--libraries/base/Data/Foldable.hs10
1 files changed, 10 insertions, 0 deletions
diff --git a/libraries/base/Data/Foldable.hs b/libraries/base/Data/Foldable.hs
index 08ba9d49ed..2656efa103 100644
--- a/libraries/base/Data/Foldable.hs
+++ b/libraries/base/Data/Foldable.hs
@@ -296,6 +296,16 @@ instance Foldable [] where
sum = List.sum
toList = id
+-- | @since 4.9.0.0
+instance Foldable NonEmpty where
+ foldr f z ~(a :| as) = f a (List.foldr f z as)
+ foldl f z ~(a :| as) = List.foldl f (f z a) as
+ foldl1 f ~(a :| as) = List.foldl f a as
+ foldMap f ~(a :| as) = f a `mappend` foldMap f as
+ fold ~(m :| ms) = m `mappend` fold ms
+ length (_ :| as) = 1 + List.length as
+ toList ~(a :| as) = a : as
+
-- | @since 4.7.0.0
instance Foldable (Either a) where
foldMap _ (Left _) = mempty