Community
Modules 26

Data.Semigroup.Foldable

provisional

Re-exports a subset of the Data.Foldable1 module along with some additional combinators that require Foldable1 constraints.

class (Foldable t) => Foldable1 (t :: Type -> Type)

Non-empty data structures that can be folded.

Instances define at least one of foldMap1 or foldrMap1.

fold1 :: (Semigroup m) => t m -> m

Given a structure with elements whose type is a Semigroup, combine them via the semigroup's (<>) operator.

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

Map each element of the structure to a semigroup, and combine the results.

toNonEmpty :: t a -> NonEmpty a

List of elements of a structure, from left to right.

intercalate1 :: (Foldable1 t, Semigroup m) => m -> t m -> m

Insert an m between each pair of t m.

foldrM1 :: (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.

foldlM1 :: (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.

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

Insert m between each pair of m derived from a.

>>> intercalateMap1 " " show $ True :| [False, True]
"True False True"
>>> intercalateMap1 " " show $ True :| []
"True"

traverse1_ :: (Foldable1 t, Apply f) => (a -> f b) -> t a -> f ()

for1_ :: (Foldable1 t, Apply f) => t a -> (a -> f b) -> f ()

sequenceA1_ :: (Foldable1 t, Apply f) => t (f a) -> f ()

foldMapDefault1 :: (Foldable1 t, Monoid m) => (a -> m) -> t a -> m

Usable default for foldMap, but only if you define foldMap1 yourself

asum1 :: (Foldable1 t, Alt m) => t (m a) -> m a

gfold1 :: (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 example data Bar a = MkBar a Int

gfoldMap1 :: (Foldable1 (Rep1 t), Generic1 t, Semigroup m) => (a -> m) -> t a -> m

Generic foldMap1. Caveats are the same as for gfold1.

gtoNonEmpty :: (Foldable1 (Rep1 t), Generic1 t) => t a -> NonEmpty a

Generic toNonEmpty. Caveats are the same as for gfold1.

Instances

4
  • instance Semigroup a => Semigroup (JoinWith a)
  • instance Apply f => Semigroup (Act f a)
  • instance Functor f => Functor (Act f)
  • instance Alt f => Semigroup (Alt_ f a)
Maintainer
Edward Kmett <ekmett@gmail.com>
Portability
portable
Copyright
(C) 2011-2015 Edward Kmett
License
BSD-style (see the file LICENSE)
Build record and source files

Community contribution. The service has not verified this documentation.

Target: Linux on x86-64. Some inferred types and resolved links are not available.

Generator: aihc-haddock-858b1951-web-1

Metadata snapshot: 4ac4693dc44e2bb370a93502d1bf29784374032a00ad7b3d02803e3d433c0b16

Open the dependency plan · Download the documentation model

Import a package

Enter a package name and an exact version from Hackage. The site contains imported versions only.