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 | Haskell98 |
Data.Semigroup.Foldable
Description
Synopsis
- class Foldable t => NonEmptyFoldable t where
- intercalateNE :: (NonEmptyFoldable t, Semigroup m) => m -> t m -> m
- intercalateMapNE :: (NonEmptyFoldable t, Semigroup m) => m -> (a -> m) -> t a -> m
- traverseNE_ :: (NonEmptyFoldable t, Semiapplicative f) => (a -> f b) -> t a -> f ()
- for1_ :: (NonEmptyFoldable t, Semiapplicative f) => t a -> (a -> f b) -> f ()
- sequenceA1_ :: (NonEmptyFoldable t, Semiapplicative f) => t (f a) -> f ()
- foldMapDefaultNE :: (NonEmptyFoldable t, Monoid m) => (a -> m) -> t a -> m
- asumNE :: (NonEmptyFoldable t, Semialternative m) => t (m a) -> m a
- foldrMNE :: (NonEmptyFoldable t, Monad m) => (a -> a -> m a) -> t a -> m a
- foldlMNE :: (NonEmptyFoldable t, Monad m) => (a -> a -> m a) -> t a -> m a
Documentation
class Foldable t => NonEmptyFoldable t where Source #
Methods
foldNE :: Semigroup m => t m -> m Source #
foldMapNE :: Semigroup m => (a -> m) -> t a -> m Source #
toNonEmpty :: t a -> NonEmpty a Source #
Instances
intercalateNE :: (NonEmptyFoldable t, Semigroup m) => m -> t m -> m Source #
Insert an m
between each pair of 't m'. Equivalent to
intercalateMapNE
with id
as the second argument.
>>>
intercalateNE ", " $ "hello" :| ["how", "are", "you"]
"hello, how, are, you"
>>>
intercalateNE ", " $ "hello" :| []
"hello"
>>>
intercalateNE mempty $ "I" :| ["Am", "Fine", "You?"]
"IAmFineYou?"
intercalateMapNE :: (NonEmptyFoldable t, Semigroup m) => m -> (a -> m) -> t a -> m Source #
Insert m
between each pair of m
derived from a
.
>>>
intercalateMapNE " " show $ True :| [False, True]
"True False True"
>>>
intercalateMapNE " " show $ True :| []
"True"
traverseNE_ :: (NonEmptyFoldable t, Semiapplicative f) => (a -> f b) -> t a -> f () Source #
for1_ :: (NonEmptyFoldable t, Semiapplicative f) => t a -> (a -> f b) -> f () Source #
sequenceA1_ :: (NonEmptyFoldable t, Semiapplicative f) => t (f a) -> f () Source #
foldMapDefaultNE :: (NonEmptyFoldable t, Monoid m) => (a -> m) -> t a -> m Source #
Usable default for foldMap, but only if you define foldMapNE yourself
asumNE :: (NonEmptyFoldable t, Semialternative m) => t (m a) -> m a Source #
foldrMNE :: (NonEmptyFoldable t, Monad m) => (a -> a -> m a) -> t a -> m a Source #
Monadic fold over the elements of a non-empty structure, associating to the right, i.e. from right to left.
let g = (=<<) . f in foldrMNE f (x1 :| [x2, ..., xn]) == x1 `g` (x2 `g` ... (xn-1 `f` xn)...)
foldlMNE :: (NonEmptyFoldable t, Monad m) => (a -> a -> m a) -> t a -> m a Source #
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 foldlMNE f (x1 :| [x2, ..., xn]) == (...((x1 `f` x2) `g` x2) `g`...) `g` xn