packages feed

papa-0.7.0: src/Papa/Base/Data/Monoid.hs

{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -Wall #-}

-- | Monoids, with 'mconcat' generalised to any 'Foldable'.
module Papa.Base.Data.Monoid (
  module P,
  mconcat,
) where

import Data.Foldable (Foldable, fold)
import Data.Monoid as P (
  Monoid (mappend, mempty),
 )

-- $setup
-- >>> :set -XNoImplicitPrelude
-- >>> import Papa
-- >>> import Hedgehog
-- >>> import qualified Hedgehog.Gen as Gen
-- >>> import qualified Hedgehog.Range as Range
-- >>> let genStrings = Gen.list (Range.linear 0 10) (Gen.string (Range.linear 0 5) Gen.alpha)

-- | 'fold', under the name of "Data.Monoid"'s @mconcat@.
--
-- ==== __Examples__
--
-- >>> mconcat ["a", "b", "c"]
-- "abc"
--
-- >>> mconcat (Just "a")
-- "a"
--
-- >>> check $ withTests 100 $ property $ do xs <- forAll genStrings; mconcat xs === foldr (<>) mempty xs
-- ...passed 100 tests.
-- True
--
-- @since 0.1.0
mconcat :: (Foldable f, Monoid a) => f a -> a
mconcat =
  fold
{-# INLINE mconcat #-}