ListLike-4.7.8.2: Generalized support for list-like structures

Copyright | Copyright (C) 2007 John Goerzen
License | BSD3
Maintainer | David Fox <dsf@seereason.com>, Andreas Abel
Stability | stable
Portability | portable
Safe Haskell | Safe-Inferred
Language | Haskell2010

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
- 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 #

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.

Minimal complete definition

foldl, foldr

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

Instances details

FoldableLL CharString Char # |
Instance details Defined in Data.ListLike.CharString Methods foldl :: (a -> Char -> a) -> a -> CharString -> a # foldl' :: (a -> Char -> a) -> a -> CharString -> a # foldl1 :: (Char -> Char -> Char) -> CharString -> Char # foldr :: (Char -> b -> b) -> b -> CharString -> b # foldr' :: (Char -> b -> b) -> b -> CharString -> b # foldr1 :: (Char -> Char -> Char) -> CharString -> Char #
FoldableLL CharStringLazy Char # |

Instance details

Defined in Data.ListLike.CharString

Methods

foldl :: (a -> Char -> a) -> a -> CharStringLazy -> a #

foldl' :: (a -> Char -> a) -> a -> CharStringLazy -> a #

foldl1 :: (Char -> Char -> Char) -> CharStringLazy -> Char #

foldr :: (Char -> b -> b) -> b -> CharStringLazy -> b #

foldr' :: (Char -> b -> b) -> b -> CharStringLazy -> b #

foldr1 :: (Char -> Char -> Char) -> CharStringLazy -> Char #

FoldableLL Chars Char # |
Instance details Defined in Data.ListLike.Chars Methods foldl :: (a -> Char -> a) -> a -> Chars -> a # foldl' :: (a -> Char -> a) -> a -> Chars -> a # foldl1 :: (Char -> Char -> Char) -> Chars -> Char # foldr :: (Char -> b -> b) -> b -> Chars -> b # foldr' :: (Char -> b -> b) -> b -> Chars -> b # foldr1 :: (Char -> Char -> Char) -> Chars -> Char #
FoldableLL ByteString Word8 # |
Instance details Defined in Data.ListLike.Instances Methods foldl :: (a -> Word8 -> a) -> a -> ByteString -> a # foldl' :: (a -> Word8 -> a) -> a -> ByteString -> a # foldl1 :: (Word8 -> Word8 -> Word8) -> ByteString -> Word8 # foldr :: (Word8 -> b -> b) -> b -> ByteString -> b # foldr' :: (Word8 -> b -> b) -> b -> ByteString -> b # foldr1 :: (Word8 -> Word8 -> Word8) -> ByteString -> Word8 #
FoldableLL ByteString Word8 # |
Instance details Defined in Data.ListLike.Instances Methods foldl :: (a -> Word8 -> a) -> a -> ByteString -> a # foldl' :: (a -> Word8 -> a) -> a -> ByteString -> a # foldl1 :: (Word8 -> Word8 -> Word8) -> ByteString -> Word8 # foldr :: (Word8 -> b -> b) -> b -> ByteString -> b # foldr' :: (Word8 -> b -> b) -> b -> ByteString -> b # foldr1 :: (Word8 -> Word8 -> Word8) -> ByteString -> Word8 #
FoldableLL Text Char # |
Instance details Defined in Data.ListLike.Text.Text Methods foldl :: (a -> Char -> a) -> a -> Text -> a # foldl' :: (a -> Char -> a) -> a -> Text -> a # foldl1 :: (Char -> Char -> Char) -> Text -> Char # foldr :: (Char -> b -> b) -> b -> Text -> b # foldr' :: (Char -> b -> b) -> b -> Text -> b # foldr1 :: (Char -> Char -> Char) -> Text -> Char #
FoldableLL Builder Char # |
Instance details Defined in Data.ListLike.Text.Builder Methods foldl :: (a -> Char -> a) -> a -> Builder -> a # foldl' :: (a -> Char -> a) -> a -> Builder -> a # foldl1 :: (Char -> Char -> Char) -> Builder -> Char # foldr :: (Char -> b -> b) -> b -> Builder -> b # foldr' :: (Char -> b -> b) -> b -> Builder -> b # foldr1 :: (Char -> Char -> Char) -> Builder -> Char #
FoldableLL Text Char # |
Instance details Defined in Data.ListLike.Text.TextLazy Methods foldl :: (a -> Char -> a) -> a -> Text -> a # foldl' :: (a -> Char -> a) -> a -> Text -> a # foldl1 :: (Char -> Char -> Char) -> Text -> Char # foldr :: (Char -> b -> b) -> b -> Text -> b # foldr' :: (Char -> b -> b) -> b -> Text -> b # foldr1 :: (Char -> Char -> Char) -> Text -> Char #
FoldableLL (Seq a) a # |
Instance details Defined in Data.ListLike.Instances Methods foldl :: (a0 -> a -> a0) -> a0 -> Seq a -> a0 # foldl' :: (a0 -> a -> a0) -> a0 -> Seq a -> a0 # foldl1 :: (a -> a -> a) -> Seq a -> a # foldr :: (a -> b -> b) -> b -> Seq a -> b # foldr' :: (a -> b -> b) -> b -> Seq a -> b # foldr1 :: (a -> a -> a) -> Seq a -> a #
FoldableLL (DList a) a # |
Instance details Defined in Data.ListLike.DList Methods foldl :: (a0 -> a -> a0) -> a0 -> DList a -> a0 # foldl' :: (a0 -> a -> a0) -> a0 -> DList a -> a0 # foldl1 :: (a -> a -> a) -> DList a -> a # foldr :: (a -> b -> b) -> b -> DList a -> b # foldr' :: (a -> b -> b) -> b -> DList a -> b # foldr1 :: (a -> a -> a) -> DList a -> a #
FoldableLL (FMList a) a # |
Instance details Defined in Data.ListLike.FMList Methods foldl :: (a0 -> a -> a0) -> a0 -> FMList a -> a0 # foldl' :: (a0 -> a -> a0) -> a0 -> FMList a -> a0 # foldl1 :: (a -> a -> a) -> FMList a -> a # foldr :: (a -> b -> b) -> b -> FMList a -> b # foldr' :: (a -> b -> b) -> b -> FMList a -> b # foldr1 :: (a -> a -> a) -> FMList a -> a #
FoldableLL (UTF8 ByteString) Char # |

Instance details

Defined in Data.ListLike.UTF8

Methods

foldl :: (a -> Char -> a) -> a -> UTF8 ByteString -> a #

foldl' :: (a -> Char -> a) -> a -> UTF8 ByteString -> a #

foldl1 :: (Char -> Char -> Char) -> UTF8 ByteString -> Char #

foldr :: (Char -> b -> b) -> b -> UTF8 ByteString -> b #

foldr' :: (Char -> b -> b) -> b -> UTF8 ByteString -> b #

foldr1 :: (Char -> Char -> Char) -> UTF8 ByteString -> Char #

FoldableLL (UTF8 ByteString) Char # |

Instance details

Defined in Data.ListLike.UTF8

Methods

foldl :: (a -> Char -> a) -> a -> UTF8 ByteString -> a #

foldl' :: (a -> Char -> a) -> a -> UTF8 ByteString -> a #

foldl1 :: (Char -> Char -> Char) -> UTF8 ByteString -> Char #

foldr :: (Char -> b -> b) -> b -> UTF8 ByteString -> b #

foldr' :: (Char -> b -> b) -> b -> UTF8 ByteString -> b #

foldr1 :: (Char -> Char -> Char) -> UTF8 ByteString -> Char #

FoldableLL (Vector a) a # |
Instance details Defined in Data.ListLike.Vector.Vector Methods foldl :: (a0 -> a -> a0) -> a0 -> Vector a -> a0 # foldl' :: (a0 -> a -> a0) -> a0 -> Vector a -> a0 # foldl1 :: (a -> a -> a) -> Vector a -> a # foldr :: (a -> b -> b) -> b -> Vector a -> b # foldr' :: (a -> b -> b) -> b -> Vector a -> b # foldr1 :: (a -> a -> a) -> Vector a -> a #
Storable a => FoldableLL (Vector a) a # |
Instance details Defined in Data.ListLike.Vector.Storable Methods foldl :: (a0 -> a -> a0) -> a0 -> Vector a -> a0 # foldl' :: (a0 -> a -> a0) -> a0 -> Vector a -> a0 # foldl1 :: (a -> a -> a) -> Vector a -> a # foldr :: (a -> b -> b) -> b -> Vector a -> b # foldr' :: (a -> b -> b) -> b -> Vector a -> b # foldr1 :: (a -> a -> a) -> Vector a -> a #
Unbox a => FoldableLL (Vector a) a # |
Instance details Defined in Data.ListLike.Vector.Unboxed Methods foldl :: (a0 -> a -> a0) -> a0 -> Vector a -> a0 # foldl' :: (a0 -> a -> a0) -> a0 -> Vector a -> a0 # foldl1 :: (a -> a -> a) -> Vector a -> a # foldr :: (a -> b -> b) -> b -> Vector a -> b # foldr' :: (a -> b -> b) -> b -> Vector a -> b # foldr1 :: (a -> a -> a) -> Vector a -> a #
FoldableLL [a] a # |
Instance details Defined in Data.ListLike.FoldableLL Methods foldl :: (a0 -> a -> a0) -> a0 -> [a] -> a0 # foldl' :: (a0 -> a -> a0) -> a0 -> [a] -> a0 # foldl1 :: (a -> a -> a) -> [a] -> a # foldr :: (a -> b -> b) -> b -> [a] -> b # foldr' :: (a -> b -> b) -> b -> [a] -> b # foldr1 :: (a -> a -> a) -> [a] -> a #
Vector v a => FoldableLL (v a) a # |
Instance details Defined in Data.ListLike.Vector.Generic Methods foldl :: (a0 -> a -> a0) -> a0 -> v a -> a0 # foldl' :: (a0 -> a -> a0) -> a0 -> v a -> a0 # foldl1 :: (a -> a -> a) -> v a -> a # foldr :: (a -> b -> b) -> b -> v a -> b # foldr' :: (a -> b -> b) -> b -> v a -> b # foldr1 :: (a -> a -> a) -> v a -> a #
Ix i => FoldableLL (Array i e) e # |
Instance details Defined in Data.ListLike.Instances Methods foldl :: (a -> e -> a) -> a -> Array i e -> a # foldl' :: (a -> e -> a) -> a -> Array i e -> a # foldl1 :: (e -> e -> e) -> Array i e -> e # foldr :: (e -> b -> b) -> b -> Array i e -> b # foldr' :: (e -> b -> b) -> b -> Array i e -> b # foldr1 :: (e -> e -> e) -> 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

foldM :: (Monad m, FoldableLL full item) => (a -> item -> m a) -> a -> full -> m a #

Monadic version of left fold, similar to `foldM`.

sequence_ :: (Monad m, FoldableLL full (m item)) => full -> m () #

Evaluate each action, ignoring the results. Same as ``mapM_` `id``.

mapM_ :: (Monad m, FoldableLL full item) => (item -> m b) -> full -> m () #

A map in monad space, discarding results.