HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulerelude-1.2.0.0Haskell2010

Relude.Extra.Foldable

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

Contains utility functions for working with tuples.

  • 2 values
  • Packagerelude-1.2.0.0
  • Exports2
  • LanguageHaskell2010
  • LicenceMIT
  • SourceFoldable.hs
valuefoldlSC :: Foldable t => (b -> a -> Either b b) -> b -> t a -> b
#

A left-associative fold that's tail-recursive but can still short-circuit. Returning a Left short-circuits and immediately returns the value inside. Returning a Right continues the fold as usual with the value inside.

Example2 expressions
foldlSC (\acc x -> if x == 0 then Left 0 else Right $! acc * x) 1 [1..6]720foldlSC (\acc x -> if x == 0 then Left 0 else Right $! acc * x) 1 (0:error "Short-circuiting should keep this from happening")0
valueaverage :: (Foldable f, Fractional a) => f a -> Maybe a
#

Given a Foldable of Fractional elements, computes the average if possible and returns Maybe element.

Example4 expressions
average [42]Just 42.0average @Double [1, 2, 3, 4]Just 2.5average @Float [1.5, 2.5, 3 ,4]Just 2.75average []Nothing