HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulerelude-1.2.0.0Haskell2010

Relude.Foldable.Fold

SPDX-License-Identifier : MIT Maintainer : Kowainik xrom.xkov@gmail.com Stability : Stable Portability : Portable

Fixes and additions to Foldable. Specifically:

  • 12 values
  • Packagerelude-1.2.0.0
  • Exports12
  • LanguageHaskell2010
  • LicenceMIT
  • SourceFold.hs
valueflipfoldl' :: Foldable f => (a -> b -> b) -> b -> f a -> b
#

Similar to foldl' but takes a function with its arguments flipped.

Example1 expression
flipfoldl' (/) 5 [2,3] :: Rational15 % 2

This function can be useful for constructing containers from lists.

valueasumMap :: (Foldable f, Alternative m) => (a -> m b) -> f a -> m b
#

Alternative version of Relude.asum that takes a function to map over.

Example1 expression
asumMap (\x -> if x > 2 then Just x else Nothing) [1..4]Just 3
valuefoldMapA
  1. :: (Semigroup b, Monoid b, Applicative m, Foldable f)
  2. => a -> m b
  3. -> f a
  4. -> m b
#

Polymorphic version of the Relude.concatMapA function.

Example1 expression
foldMapA @[Int] (Just . replicate 3) [1..3]Just [1,1,1,2,2,2,3,3,3]
valuefoldMapM :: (Monoid b, Monad m, Foldable f) => (a -> m b) -> f a -> m b
#

Polymorphic version of the Relude.concatMapM function.

Example1 expression
foldMapM @[Int] (Just . replicate 3) [1..3]Just [1,1,1,2,2,2,3,3,3]
valuesum :: (Foldable f, Num a) => f a -> a
#

Stricter version of sum.

Example1 expression
sum [1..10]55
valueelem :: (Foldable f, DisallowElem f, Eq a) => a -> f a -> Bool
#

Like elem but doesn't work on Set and HashSet for performance reasons.

Example2 expressions
elem 'x' ("abc" :: String)Falseelem False (one True :: Set Bool)...... Do not use 'elem' and 'notElem' methods from 'Foldable' on Set      Suggestions:          Instead of              elem :: (Foldable t, Eq a) => a -> t a -> Bool          use              member :: Ord a => a -> Set a -> Bool...          Instead of              notElem :: (Foldable t, Eq a) => a -> t a -> Bool          use              not . member...
valuenotElem :: (Foldable f, DisallowElem f, Eq a) => a -> f a -> Bool
#

Like notElem but doesn't work on Set and HashSet for performance reasons.

Example2 expressions
notElem 'x' ("abc" :: String)TruenotElem False (one True :: Set Bool)...... Do not use 'elem' and 'notElem' methods from 'Foldable' on Set      Suggestions:          Instead of              elem :: (Foldable t, Eq a) => a -> t a -> Bool          use              member :: Ord a => a -> Set a -> Bool...          Instead of              notElem :: (Foldable t, Eq a) => a -> t a -> Bool          use              not . member...

Monadic functions

4 declarations
valueallM :: (Foldable f, Monad m) => (a -> m Bool) -> f a -> m Bool
#

Monadic version of all.

Example3 expressions
allM (readMaybe >=> pure . even) ["6", "10"]Just TrueallM (readMaybe >=> pure . even) ["5", "aba"]Just FalseallM (readMaybe >=> pure . even) ["aba", "10"]Nothing
valueanyM :: (Foldable f, Monad m) => (a -> m Bool) -> f a -> m Bool
#

Monadic version of any.

Example3 expressions
anyM (readMaybe >=> pure . even) ["5", "10"]Just TrueanyM (readMaybe >=> pure . even) ["10", "aba"]Just TrueanyM (readMaybe >=> pure . even) ["aba", "10"]Nothing
valueandM :: (Foldable f, Monad m) => f (m Bool) -> m Bool
#

Monadic version of and.

Example5 expressions
andM [Just True, Just False]Just FalseandM [Just True]Just TrueandM [Just True, Just False, Nothing]Just FalseandM [Just True, Nothing]NothingandM [putTextLn "1" >> pure True, putTextLn "2" >> pure False, putTextLn "3" >> pure True]12False
valueorM :: (Foldable f, Monad m) => f (m Bool) -> m Bool
#

Monadic version of or.

Example3 expressions
orM [Just True, Just False]Just TrueorM [Just True, Nothing]Just TrueorM [Nothing, Just True]Nothing