summaryrefslogtreecommitdiff
path: root/libraries/base/Data/Foldable.hs
diff options
context:
space:
mode:
authorVictor Nawothnig <Victor.Nawothnig@gmail.de>2018-11-29 18:44:36 -0500
committerRyan Scott <ryan.gl.scott@gmail.com>2018-11-29 18:44:42 -0500
commit9e3aaf8b58d0f0e12e2d19b6928b6c2461d58dda (patch)
tree137b05175fe30f460c0c3d7b9db43043d2ee3a8f /libraries/base/Data/Foldable.hs
parentfe57a5bae3f8cb87637359f615c77f4afae86d46 (diff)
downloadhaskell-9e3aaf8b58d0f0e12e2d19b6928b6c2461d58dda.tar.gz
Add missing since annotations
Reviewers: hvr, bgamari, RyanGlScott Reviewed By: RyanGlScott Subscribers: RyanGlScott, rwbarton, carter GHC Trac Issues: #15930 Differential Revision: https://phabricator.haskell.org/D5379
Diffstat (limited to 'libraries/base/Data/Foldable.hs')
-rw-r--r--libraries/base/Data/Foldable.hs18
1 files changed, 18 insertions, 0 deletions
diff --git a/libraries/base/Data/Foldable.hs b/libraries/base/Data/Foldable.hs
index cc0f348e47..7134b0586e 100644
--- a/libraries/base/Data/Foldable.hs
+++ b/libraries/base/Data/Foldable.hs
@@ -159,6 +159,7 @@ class Foldable t where
-- | Right-associative fold of a structure, but with strict application of
-- the operator.
--
+ -- @since 4.6.0.0
foldr' :: (a -> b -> b) -> b -> t a -> b
foldr' f z0 xs = foldl f' id xs z0
where f' k x z = k $! f x z
@@ -206,6 +207,7 @@ class Foldable t where
--
-- @foldl f z = 'List.foldl'' f z . 'toList'@
--
+ -- @since 4.6.0.0
foldl' :: (b -> a -> b) -> b -> t a -> b
foldl' f z0 xs = foldr f' id xs z0
where f' x k z = k $! f z x
@@ -235,6 +237,8 @@ class Foldable t where
Just x -> f x y)
-- | List of elements of a structure, from left to right.
+ --
+ -- @since 4.8.0.0
toList :: t a -> [a]
{-# INLINE toList #-}
toList t = build (\ c n -> foldr c n t)
@@ -242,35 +246,49 @@ class Foldable t where
-- | Test whether the structure is empty. The default implementation is
-- optimized for structures that are similar to cons-lists, because there
-- is no general way to do better.
+ --
+ -- @since 4.8.0.0
null :: t a -> Bool
null = foldr (\_ _ -> False) True
-- | Returns the size/length of a finite structure as an 'Int'. The
-- default implementation is optimized for structures that are similar to
-- cons-lists, because there is no general way to do better.
+ --
+ -- @since 4.8.0.0
length :: t a -> Int
length = foldl' (\c _ -> c+1) 0
-- | Does the element occur in the structure?
+ --
+ -- @since 4.8.0.0
elem :: Eq a => a -> t a -> Bool
elem = any . (==)
-- | The largest element of a non-empty structure.
+ --
+ -- @since 4.8.0.0
maximum :: forall a . Ord a => t a -> a
maximum = fromMaybe (errorWithoutStackTrace "maximum: empty structure") .
getMax . foldMap (Max #. (Just :: a -> Maybe a))
-- | The least element of a non-empty structure.
+ --
+ -- @since 4.8.0.0
minimum :: forall a . Ord a => t a -> a
minimum = fromMaybe (errorWithoutStackTrace "minimum: empty structure") .
getMin . foldMap (Min #. (Just :: a -> Maybe a))
-- | The 'sum' function computes the sum of the numbers of a structure.
+ --
+ -- @since 4.8.0.0
sum :: Num a => t a -> a
sum = getSum #. foldMap Sum
-- | The 'product' function computes the product of the numbers of a
-- structure.
+ --
+ -- @since 4.8.0.0
product :: Num a => t a -> a
product = getProduct #. foldMap Product