Copyright | Copyright (C) 2007 John Goerzen |
---|---|
License | BSD3 |
Maintainer | John Lato <jwlato@gmail.com> |
Stability | provisional |
Portability | portable |
Safe Haskell | Safe-Inferred |
Language | Haskell98 |
Generic tools for data structures that can be folded.
Written by John Goerzen, jgoerzen@complete.org
- class FoldableLL full item | full -> item where
- fold :: (FoldableLL full item, Monoid item) => full -> item
- foldMap :: (FoldableLL full item, Monoid m) => (item -> m) -> full -> m
- foldM :: (Monad m, FoldableLL full item) => (a -> item -> m a) -> a -> full -> m a
- sequence_ :: (Monad m, FoldableLL full (m item)) => full -> m ()
- mapM_ :: (Monad m, FoldableLL full item) => (item -> m b) -> full -> m ()
FoldableLL Class
class FoldableLL full item | full -> item where Source
This is the primary class for structures that are to be considered
foldable. A minimum complete definition provides foldl
and foldr
.
Instances of FoldableLL
can be folded, and can be many and varied.
These functions are used heavily in Data.ListLike.
foldl :: (a -> item -> a) -> a -> full -> a Source
Left-associative fold
foldl' :: (a -> item -> a) -> a -> full -> a Source
Strict version of foldl
.
foldl1 :: (item -> item -> item) -> full -> item Source
A variant of foldl
with no base case. Requires at least 1
list element.
foldr :: (item -> b -> b) -> b -> full -> b Source
Right-associative fold
foldr' :: (item -> b -> b) -> b -> full -> b Source
Strict version of foldr
foldr1 :: (item -> item -> item) -> full -> item Source
Like foldr
, but with no starting value
FoldableLL ByteString Word8 | |
FoldableLL ByteString Word8 | |
FoldableLL Text Char | |
FoldableLL Text Char | |
FoldableLL CharStringLazy Char | |
FoldableLL CharString Char | |
FoldableLL [a] a | |
Vector v a => FoldableLL (v a) a | |
FoldableLL (Seq a) a | |
FoldableLL (DList a) a | |
FoldableLL (FMList a) a | |
FoldableLL (Vector a) a | |
Unbox a => FoldableLL (Vector a) a | |
Storable a => FoldableLL (Vector a) a | |
Ix i => FoldableLL (Array i e) e |
Utilities
fold :: (FoldableLL full item, Monoid item) => full -> item Source
foldMap :: (FoldableLL full item, Monoid m) => (item -> m) -> full -> m Source
Map each element to a monoid, then combine the results
foldM :: (Monad m, FoldableLL full item) => (a -> item -> m a) -> a -> full -> m a Source
Monadic version of left fold, similar to foldM
.
sequence_ :: (Monad m, FoldableLL full (m item)) => full -> m () Source
mapM_ :: (Monad m, FoldableLL full item) => (item -> m b) -> full -> m () Source
A map in monad space, discarding results.