Data.Semigroup.Foldable

semigroupoids-5.3.7: Semigroupoids: Category sans id

Copyright | (C) 2011-2015 Edward Kmett
License | BSD-style (see the file LICENSE)
Maintainer | Edward Kmett <ekmett@gmail.com>
Stability | provisional
Portability | portable
Safe Haskell | Safe
Language | Haskell2010

Data.Semigroup.Foldable

Description

Synopsis

- class Foldable t => Foldable1 t where
  - fold1 :: Semigroup m => t m -> m
  - foldMap1 :: Semigroup m => (a -> m) -> t a -> m
  - toNonEmpty :: t a -> NonEmpty a
- intercalate1 :: (Foldable1 t, Semigroup m) => m -> t m -> m
- intercalateMap1 :: (Foldable1 t, Semigroup m) => m -> (a -> m) -> t a -> m
- 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
- asum1 :: (Foldable1 t, Alt m) => t (m a) -> m a
- foldrM1 :: (Foldable1 t, Monad m) => (a -> a -> m a) -> t a -> m a
- foldlM1 :: (Foldable1 t, Monad m) => (a -> a -> m a) -> t a -> m a

# Documentation

class Foldable t => Foldable1 t where #

Minimal complete definition

Nothing

Methods

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

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

toNonEmpty :: t a -> NonEmpty a #

#### Instances

Instances details

Foldable1 Complex # |
Instance details Defined in Data.Semigroup.Foldable.Class Methods fold1 :: Semigroup m => Complex m -> m # foldMap1 :: Semigroup m => (a -> m) -> Complex a -> m # toNonEmpty :: Complex a -> NonEmpty a #
Foldable1 Identity # |
Instance details Defined in Data.Semigroup.Foldable.Class Methods fold1 :: Semigroup m => Identity m -> m # foldMap1 :: Semigroup m => (a -> m) -> Identity a -> m # toNonEmpty :: Identity a -> NonEmpty a #
Foldable1 First # |
Instance details Defined in Data.Semigroup.Foldable.Class Methods fold1 :: Semigroup m => First m -> m # foldMap1 :: Semigroup m => (a -> m) -> First a -> m # toNonEmpty :: First a -> NonEmpty a #
Foldable1 Last # |
Instance details Defined in Data.Semigroup.Foldable.Class Methods fold1 :: Semigroup m => Last m -> m # foldMap1 :: Semigroup m => (a -> m) -> Last a -> m # toNonEmpty :: Last a -> NonEmpty a #
Foldable1 Max # |
Instance details Defined in Data.Semigroup.Foldable.Class Methods fold1 :: Semigroup m => Max m -> m # foldMap1 :: Semigroup m => (a -> m) -> Max a -> m # toNonEmpty :: Max a -> NonEmpty a #
Foldable1 Min # |
Instance details Defined in Data.Semigroup.Foldable.Class Methods fold1 :: Semigroup m => Min m -> m # foldMap1 :: Semigroup m => (a -> m) -> Min a -> m # toNonEmpty :: Min a -> NonEmpty a #
Foldable1 Dual # |
Instance details Defined in Data.Semigroup.Foldable.Class Methods fold1 :: Semigroup m => Dual m -> m # foldMap1 :: Semigroup m => (a -> m) -> Dual a -> m # toNonEmpty :: Dual a -> NonEmpty a #
Foldable1 Product # |
Instance details Defined in Data.Semigroup.Foldable.Class Methods fold1 :: Semigroup m => Product m -> m # foldMap1 :: Semigroup m => (a -> m) -> Product a -> m # toNonEmpty :: Product a -> NonEmpty a #
Foldable1 Sum # |
Instance details Defined in Data.Semigroup.Foldable.Class Methods fold1 :: Semigroup m => Sum m -> m # foldMap1 :: Semigroup m => (a -> m) -> Sum a -> m # toNonEmpty :: Sum a -> NonEmpty a #
Foldable1 Par1 # |
Instance details Defined in Data.Semigroup.Foldable.Class Methods fold1 :: Semigroup m => Par1 m -> m # foldMap1 :: Semigroup m => (a -> m) -> Par1 a -> m # toNonEmpty :: Par1 a -> NonEmpty a #
Foldable1 Tree # |
Instance details Defined in Data.Semigroup.Foldable.Class Methods fold1 :: Semigroup m => Tree m -> m # foldMap1 :: Semigroup m => (a -> m) -> Tree a -> m # toNonEmpty :: Tree a -> NonEmpty a #
Foldable1 NonEmpty # |
Instance details Defined in Data.Semigroup.Foldable.Class Methods fold1 :: Semigroup m => NonEmpty m -> m # foldMap1 :: Semigroup m => (a -> m) -> NonEmpty a -> m # toNonEmpty :: NonEmpty a -> NonEmpty a #
Foldable1 (V1 :: Type -> Type) # |
Instance details Defined in Data.Semigroup.Foldable.Class Methods fold1 :: Semigroup m => V1 m -> m # foldMap1 :: Semigroup m => (a -> m) -> V1 a -> m # toNonEmpty :: V1 a -> NonEmpty a #
Foldable1 f => Foldable1 (Lift f) # |
Instance details Defined in Data.Semigroup.Foldable.Class Methods fold1 :: Semigroup m => Lift f m -> m # foldMap1 :: Semigroup m => (a -> m) -> Lift f a -> m # toNonEmpty :: Lift f a -> NonEmpty a #
Foldable1 ((,) a) # |
Instance details Defined in Data.Semigroup.Foldable.Class Methods fold1 :: Semigroup m => (a, m) -> m # foldMap1 :: Semigroup m => (a0 -> m) -> (a, a0) -> m # toNonEmpty :: (a, a0) -> NonEmpty a0 #
Foldable1 f => Foldable1 (Alt f) # |
Instance details Defined in Data.Semigroup.Foldable.Class Methods fold1 :: Semigroup m => Alt f m -> m # foldMap1 :: Semigroup m => (a -> m) -> Alt f a -> m # toNonEmpty :: Alt f a -> NonEmpty a #
Foldable1 f => Foldable1 (Rec1 f) # |
Instance details Defined in Data.Semigroup.Foldable.Class Methods fold1 :: Semigroup m => Rec1 f m -> m # foldMap1 :: Semigroup m => (a -> m) -> Rec1 f a -> m # toNonEmpty :: Rec1 f a -> NonEmpty a #
Bifoldable1 p => Foldable1 (Join p) # |
Instance details Defined in Data.Semigroup.Foldable.Class Methods fold1 :: Semigroup m => Join p m -> m # foldMap1 :: Semigroup m => (a -> m) -> Join p a -> m # toNonEmpty :: Join p a -> NonEmpty a #
Foldable1 (Tagged a) # |
Instance details Defined in Data.Semigroup.Foldable.Class Methods fold1 :: Semigroup m => Tagged a m -> m # foldMap1 :: Semigroup m => (a0 -> m) -> Tagged a a0 -> m # toNonEmpty :: Tagged a a0 -> NonEmpty a0 #
Foldable1 f => Foldable1 (Backwards f) # |
Instance details Defined in Data.Semigroup.Foldable.Class Methods fold1 :: Semigroup m => Backwards f m -> m # foldMap1 :: Semigroup m => (a -> m) -> Backwards f a -> m # toNonEmpty :: Backwards f a -> NonEmpty a #
Foldable1 m => Foldable1 (IdentityT m) # |
Instance details Defined in Data.Semigroup.Foldable.Class Methods fold1 :: Semigroup m0 => IdentityT m m0 -> m0 # foldMap1 :: Semigroup m0 => (a -> m0) -> IdentityT m a -> m0 # toNonEmpty :: IdentityT m a -> NonEmpty a #
Foldable1 f => Foldable1 (Reverse f) # |
Instance details Defined in Data.Semigroup.Foldable.Class Methods fold1 :: Semigroup m => Reverse f m -> m # foldMap1 :: Semigroup m => (a -> m) -> Reverse f a -> m # toNonEmpty :: Reverse f a -> NonEmpty a #
(Foldable1 f, Foldable1 g) => Foldable1 (Product f g) # |
Instance details Defined in Data.Semigroup.Foldable.Class Methods fold1 :: Semigroup m => Product f g m -> m # foldMap1 :: Semigroup m => (a -> m) -> Product f g a -> m # toNonEmpty :: Product f g a -> NonEmpty a #
(Foldable1 f, Foldable1 g) => Foldable1 (Sum f g) # |
Instance details Defined in Data.Semigroup.Foldable.Class Methods fold1 :: Semigroup m => Sum f g m -> m # foldMap1 :: Semigroup m => (a -> m) -> Sum f g a -> m # toNonEmpty :: Sum f g a -> NonEmpty a #
(Foldable1 f, Foldable1 g) => Foldable1 (f :*: g) # |
Instance details Defined in Data.Semigroup.Foldable.Class Methods fold1 :: Semigroup m => (f :*: g) m -> m # foldMap1 :: Semigroup m => (a -> m) -> (f :*: g) a -> m # toNonEmpty :: (f :*: g) a -> NonEmpty a #
(Foldable1 f, Foldable1 g) => Foldable1 (f :+: g) # |
Instance details Defined in Data.Semigroup.Foldable.Class Methods fold1 :: Semigroup m => (f :+: g) m -> m # foldMap1 :: Semigroup m => (a -> m) -> (f :+: g) a -> m # toNonEmpty :: (f :+: g) a -> NonEmpty a #
(Foldable1 f, Foldable1 g) => Foldable1 (Compose f g) # |
Instance details Defined in Data.Semigroup.Foldable.Class Methods fold1 :: Semigroup m => Compose f g m -> m # foldMap1 :: Semigroup m => (a -> m) -> Compose f g a -> m # toNonEmpty :: Compose f g a -> NonEmpty a #
(Foldable1 f, Foldable1 g) => Foldable1 (f :.: g) # |
Instance details Defined in Data.Semigroup.Foldable.Class Methods fold1 :: Semigroup m => (f :.: g) m -> m # foldMap1 :: Semigroup m => (a -> m) -> (f :.: g) a -> m # toNonEmpty :: (f :.: g) a -> NonEmpty a #
Foldable1 f => Foldable1 (M1 i c f) # |
Instance details Defined in Data.Semigroup.Foldable.Class Methods fold1 :: Semigroup m => M1 i c f m -> m # foldMap1 :: Semigroup m => (a -> m) -> M1 i c f a -> m # toNonEmpty :: M1 i c f a -> NonEmpty a #
Foldable1 g => Foldable1 (Joker g a) # |
Instance details Defined in Data.Semigroup.Foldable.Class Methods fold1 :: Semigroup m => Joker g a m -> m # foldMap1 :: Semigroup m => (a0 -> m) -> Joker g a a0 -> m # toNonEmpty :: Joker g a a0 -> NonEmpty a0 #

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

Insert an `m` between each pair of `t m`. Equivalent to `intercalateMap1` with `id` as the second argument.

    >>> intercalate1 ", " $ "hello" :| ["how", "are", "you"]
    "hello, how, are, you"

    >>> intercalate1 ", " $ "hello" :| []
    "hello"

    >>> intercalate1 mempty $ "I" :| ["Am", "Fine", "You?"]
    "IAmFineYou?"

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 #

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, i.e. from right to left.

    let g = (=<<) . f
    in foldrM1 f (x1 :| [x2, ..., xn]) == x1 `g` (x2 `g` ... (xn-1 `f` xn)...)

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, i.e. from left to right.

    let g = flip $ (=<<) . f
    in foldlM1 f (x1 :| [x2, ..., xn]) == (...((x1 `f` x2) `g` x2) `g`...) `g` xn