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

Modulerebase-1.21.2Haskell2010

Rebase.Data.Semigroup.Foldable

  • 1 class
  • 12 values
  • Packagerebase-1.21.2
  • Exports13
  • LanguageHaskell2010
  • LicenceMIT
  • SourceFoldable1.hs
classclass Foldable t => Foldable1 (t :: Type -> Type) where
#

Non-empty data structures that can be folded.

Methods

  • fold1 :: Semigroup m => t m -> m

    Given a structure with elements whose type is a Semigroup, combine them via the semigroup's (<>) operator. This fold is right-associative and lazy in the accumulator. When you need a strict left-associative fold, use foldMap1' instead, with id as the map.

  • foldMap1 :: Semigroup m => (a -> m) -> t a -> m

    Map each element of the structure to a semigroup, and combine the results with (<>). This fold is right-associative and lazy in the accumulator. For strict left-associative folds consider foldMap1' instead.

    Example1 expression
    foldMap1 (:[]) (1 :| [2, 3, 4])[1,2,3,4]
  • toNonEmpty :: t a -> NonEmpty a

    NonEmpty list of elements of a structure, from left to right.

    Example1 expression
    toNonEmpty (Identity 2)2 :| []
Instances43Foldable1, …
valueintercalate1 :: (Foldable1 t, Semigroup m) => m -> t m -> m
#

Insert an m between each pair of t m.

Example1 expression
intercalate1 ", " $ "hello" :| ["how", "are", "you"]"hello, how, are, you"
Example1 expression
intercalate1 ", " $ "hello" :| []"hello"
Example1 expression
intercalate1 mempty $ "I" :| ["Am", "Fine", "You?"]"IAmFineYou?"
valuefoldlM1 :: (Foldable1 t, Monad m) => (a -> a -> m a) -> t a -> m a
#

Monadic fold over the elements of a non-empty structure, associating to the left, i.e. from left to right.

valuefoldrM1 :: (Foldable1 t, Monad m) => (a -> a -> m a) -> t a -> m a
#

Monadic fold over the elements of a non-empty structure, associating to the right, i.e. from right to left.

valuegfold1 :: (Foldable1 (Rep1 t), Generic1 t, Semigroup m) => t m -> m
#

Generic fold1. Caveats:

  1. Will not compile if t is an empty constructor.

  2. Will not compile if t has some fields that don't mention a, for exmaple data Bar a = MkBar a Int

valueintercalateMap1 :: (Foldable1 t, Semigroup m) => m -> (a -> m) -> t a -> m
#

Insert m between each pair of m derived from a.

Example1 expression
intercalateMap1 " " show $ True :| [False, True]"True False True"
Example1 expression
intercalateMap1 " " show $ True :| []"True"