Data.ListLike.FoldableLL

ListLike-3.1.5: Generic support for list-like structures

Portability | portable
Stability | provisional
Maintainer | John Lato <jwlato@gmail.com>
Safe Haskell | Safe-Infered

Data.ListLike.FoldableLL

Contents

- FoldableLL Class
- Utilities

Description

Generic tools for data structures that can be folded.

Written by John Goerzen, jgoerzen@complete.org

Synopsis

- class FoldableLL full item | full -> item where
  - foldl :: (a -> item -> a) -> a -> full -> a
  - foldl' :: (a -> item -> a) -> a -> full -> a
  - foldl1 :: (item -> item -> item) -> full -> item
  - foldr :: (item -> b -> b) -> b -> full -> b
  - foldr' :: (item -> b -> b) -> b -> full -> b
  - foldr1 :: (item -> item -> item) -> full -> item
- fold :: (FoldableLL full item, Monoid item) => full -> item
- foldMap :: (FoldableLL full item, Monoid m) => (item -> m) -> full -> m

# FoldableLL Class

class FoldableLL full item | full -> item where

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.

Methods

foldl :: (a -> item -> a) -> a -> full -> a

Left-associative fold

foldl' :: (a -> item -> a) -> a -> full -> a

Strict version of `foldl`.

foldl1 :: (item -> item -> item) -> full -> item

A variant of `foldl` with no base case. Requires at least 1 list element.

foldr :: (item -> b -> b) -> b -> full -> b

Right-associative fold

foldr' :: (item -> b -> b) -> b -> full -> b

Strict version of `foldr`

foldr1 :: (item -> item -> item) -> full -> item

Like `foldr`, but with no starting value

Instances

FoldableLL ByteString Word8 |
FoldableLL ByteString Word8 |
FoldableLL CharStringLazy Char |
FoldableLL CharString Char |
FoldableLL [a] a |
FoldableLL (Seq a) a |
Ix i => FoldableLL (Array i e) e |

# Utilities

fold :: (FoldableLL full item, Monoid item) => full -> item

Combine the elements of a structure using a monoid. ``fold` = `foldMap` id`

foldMap :: (FoldableLL full item, Monoid m) => (item -> m) -> full -> m

Map each element to a monoid, then combine the results