foldl-1.4.14: Composable, streaming, and efficient left folds
Safe Haskell Trustworthy
Language Haskell2010

Control.Foldl

Description

This module provides efficient and streaming left folds that you can combine using Applicative style.

Import this module qualified to avoid clashing with the Prelude:

>>> import qualified Control.Foldl as Foldl

Use fold to apply a Fold to a list:

>>> Foldl.fold Foldl.sum [1..100]
5050

Fold s are Applicative s, so you can combine them using Applicative combinators:

>>> import Control.Applicative
>>> let average = (/) <$> Foldl.sum <*> Foldl.genericLength

… or you can use do notation if you enable the ApplicativeDo language extension:

>>> :set -XApplicativeDo
>>> let average = do total <- Foldl.sum; count <- Foldl.genericLength; return (total / count)

… or you can use the fact that the Fold type implements Num to do this:

>>> let average = Foldl.sum / Foldl.genericLength

These combined folds will still traverse the list only once, streaming efficiently over the list in constant space without space leaks:

>>> Foldl.fold average [1..10000000]
5000000.5
>>> Foldl.fold ((,) <$> Foldl.minimum <*> Foldl.maximum) [1..10000000]
(Just 1,Just 10000000)

You might want to try enabling the -flate-dmd-anal flag when compiling executables that use this library to further improve performance.

Synopsis

Fold Types

data Fold a b Source #

Efficient representation of a left fold that preserves the fold's step function, initial accumulator, and extraction function

This allows the Applicative instance to assemble derived folds that traverse the container only once

A ' Fold a b' processes elements of type a and results in a value of type b .

Constructors

forall x. Fold (x -> a -> x) x (x -> b)

Fold step initial extract

Instances

Instances details
Choice Fold Source #
Instance details

Defined in Control.Foldl

Profunctor Fold Source #
Instance details

Defined in Control.Foldl

Methods

dimap :: (a -> b) -> (c -> d) -> Fold b c -> Fold a d Source #

lmap :: (a -> b) -> Fold b c -> Fold a c Source #

rmap :: (b -> c) -> Fold a b -> Fold a c Source #

(#.) :: forall a b c q. Coercible c b => q b c -> Fold a b -> Fold a c Source #

(.#) :: forall a b c q. Coercible b a => Fold b c -> q a b -> Fold a c Source #

Functor ( Fold a) Source #
Instance details

Defined in Control.Foldl

Methods

fmap :: (a0 -> b) -> Fold a a0 -> Fold a b Source #

(<$) :: a0 -> Fold a b -> Fold a a0 Source #

Applicative ( Fold a) Source #
Instance details

Defined in Control.Foldl

Comonad ( Fold a) Source #
Instance details

Defined in Control.Foldl

Extend ( Fold a) Source #
Instance details

Defined in Control.Foldl

Semigroupoid Fold Source #
Instance details

Defined in Control.Foldl

Methods

o :: forall (j :: k) (k1 :: k) (i :: k). Fold j k1 -> Fold i j -> Fold i k1 Source #

Floating b => Floating ( Fold a b) Source #
Instance details

Defined in Control.Foldl

Fractional b => Fractional ( Fold a b) Source #
Instance details

Defined in Control.Foldl

Num b => Num ( Fold a b) Source #
Instance details

Defined in Control.Foldl

Semigroup b => Semigroup ( Fold a b) Source #
Instance details

Defined in Control.Foldl

Monoid b => Monoid ( Fold a b) Source #
Instance details

Defined in Control.Foldl

data FoldM m a b Source #

Like Fold , but monadic.

A ' FoldM m a b' processes elements of type a and results in a monadic value of type m b .

Constructors

forall x. FoldM (x -> a -> m x) (m x) (x -> m b)

FoldM step initial extract

Instances

Instances details
Functor m => Profunctor ( FoldM m) Source #
Instance details

Defined in Control.Foldl

Methods

dimap :: (a -> b) -> (c -> d) -> FoldM m b c -> FoldM m a d Source #

lmap :: (a -> b) -> FoldM m b c -> FoldM m a c Source #

rmap :: (b -> c) -> FoldM m a b -> FoldM m a c Source #

(#.) :: forall a b c q. Coercible c b => q b c -> FoldM m a b -> FoldM m a c Source #

(.#) :: forall a b c q. Coercible b a => FoldM m b c -> q a b -> FoldM m a c Source #

Functor m => Functor ( FoldM m a) Source #
Instance details

Defined in Control.Foldl

Methods

fmap :: (a0 -> b) -> FoldM m a a0 -> FoldM m a b Source #

(<$) :: a0 -> FoldM m a b -> FoldM m a a0 Source #

Applicative m => Applicative ( FoldM m a) Source #
Instance details

Defined in Control.Foldl

Methods

pure :: a0 -> FoldM m a a0 Source #

(<*>) :: FoldM m a (a0 -> b) -> FoldM m a a0 -> FoldM m a b Source #

liftA2 :: (a0 -> b -> c) -> FoldM m a a0 -> FoldM m a b -> FoldM m a c Source #

(*>) :: FoldM m a a0 -> FoldM m a b -> FoldM m a b Source #

(<*) :: FoldM m a a0 -> FoldM m a b -> FoldM m a a0 Source #

Monad m => Extend ( FoldM m a) Source #
Instance details

Defined in Control.Foldl

Methods

duplicated :: FoldM m a a0 -> FoldM m a ( FoldM m a a0) Source #

extended :: ( FoldM m a a0 -> b) -> FoldM m a a0 -> FoldM m a b Source #

( Monad m, Floating b) => Floating ( FoldM m a b) Source #
Instance details

Defined in Control.Foldl

( Monad m, Fractional b) => Fractional ( FoldM m a b) Source #
Instance details

Defined in Control.Foldl

( Monad m, Num b) => Num ( FoldM m a b) Source #
Instance details

Defined in Control.Foldl

( Semigroup b, Monad m) => Semigroup ( FoldM m a b) Source #
Instance details

Defined in Control.Foldl

( Monoid b, Monad m) => Monoid ( FoldM m a b) Source #
Instance details

Defined in Control.Foldl

Folding

fold :: Foldable f => Fold a b -> f a -> b Source #

Apply a strict left Fold to a Foldable container

foldM :: ( Foldable f, Monad m) => FoldM m a b -> f a -> m b Source #

Like fold , but monadic

scan :: Fold a b -> [a] -> [b] Source #

Convert a strict left Fold into a scan

>>> Foldl.scan Foldl.length [1..5]
[0,1,2,3,4,5]

prescan :: Traversable t => Fold a b -> t a -> t b Source #

Convert a Fold into a prescan for any Traversable type

"Prescan" means that the last element of the scan is not included

>>> Foldl.prescan Foldl.length [1..5]
[0,1,2,3,4]

postscan :: Traversable t => Fold a b -> t a -> t b Source #

Convert a Fold into a postscan for any Traversable type

"Postscan" means that the first element of the scan is not included

>>> Foldl.postscan Foldl.length [1..5]
[1,2,3,4,5]

Folds

mconcat :: Monoid a => Fold a a Source #

Fold all values within a container using mappend and mempty

foldMap :: Monoid w => (a -> w) -> (w -> b) -> Fold a b Source #

Convert a " foldMap " to a Fold

head :: Fold a ( Maybe a) Source #

Get the first element of a container or return Nothing if the container is empty

last :: Fold a ( Maybe a) Source #

Get the last element of a container or return Nothing if the container is empty

lastDef :: a -> Fold a a Source #

Get the last element of a container or return a default value if the container is empty

lastN :: Int -> Fold a [a] Source #

Return the last N elements

null :: Fold a Bool Source #

Returns True if the container is empty, False otherwise

length :: Fold a Int Source #

Return the length of the container

all :: (a -> Bool ) -> Fold a Bool Source #

(all predicate) returns True if all elements satisfy the predicate, False otherwise

any :: (a -> Bool ) -> Fold a Bool Source #

(any predicate) returns True if any element satisfies the predicate, False otherwise

sum :: Num a => Fold a a Source #

Computes the sum of all elements

product :: Num a => Fold a a Source #

Computes the product of all elements

mean :: Fractional a => Fold a a Source #

Compute a numerically stable arithmetic mean of all elements

variance :: Fractional a => Fold a a Source #

Compute a numerically stable (population) variance over all elements

std :: Floating a => Fold a a Source #

Compute a numerically stable (population) standard deviation over all elements

maximum :: Ord a => Fold a ( Maybe a) Source #

Computes the maximum element

maximumBy :: (a -> a -> Ordering ) -> Fold a ( Maybe a) Source #

Computes the maximum element with respect to the given comparison function

minimum :: Ord a => Fold a ( Maybe a) Source #

Computes the minimum element

minimumBy :: (a -> a -> Ordering ) -> Fold a ( Maybe a) Source #

Computes the minimum element with respect to the given comparison function

elem :: Eq a => a -> Fold a Bool Source #

(elem a) returns True if the container has an element equal to a , False otherwise

notElem :: Eq a => a -> Fold a Bool Source #

(notElem a) returns False if the container has an element equal to a , True otherwise

find :: (a -> Bool ) -> Fold a ( Maybe a) Source #

(find predicate) returns the first element that satisfies the predicate or Nothing if no element satisfies the predicate

index :: Int -> Fold a ( Maybe a) Source #

(index n) returns the n th element of the container, or Nothing if the container has an insufficient number of elements

lookup :: Eq a => a -> Fold (a, b) ( Maybe b) Source #

(lookup a) returns the element paired with the first matching item, or Nothing if none matches

elemIndex :: Eq a => a -> Fold a ( Maybe Int ) Source #

(elemIndex a) returns the index of the first element that equals a , or Nothing if no element matches

findIndex :: (a -> Bool ) -> Fold a ( Maybe Int ) Source #

(findIndex predicate) returns the index of the first element that satisfies the predicate, or Nothing if no element satisfies the predicate

random :: FoldM IO a ( Maybe a) Source #

Pick a random element, using reservoir sampling

randomN :: Vector v a => Int -> FoldM IO a ( Maybe (v a)) Source #

Pick several random elements, using reservoir sampling

mapM_ :: Monad m => (a -> m ()) -> FoldM m a () Source #

Converts an effectful function to a fold. Specialized version of sink .

sink :: ( Monoid w, Monad m) => (a -> m w) -> FoldM m a w Source #

Converts an effectful function to a fold

sink (f <> g) = sink f <> sink g -- if `(<>)` is commutative
sink mempty = mempty

Generic Folds

genericLength :: Num b => Fold a b Source #

Like length , except with a more general Num return value

genericIndex :: Integral i => i -> Fold a ( Maybe a) Source #

Like index , except with a more general Integral argument

Container folds

list :: Fold a [a] Source #

Fold all values into a list

revList :: Fold a [a] Source #

Fold all values into a list, in reverse order

nub :: Ord a => Fold a [a] Source #

O(n log n) . Fold values into a list with duplicates removed, while preserving their first occurrences

eqNub :: Eq a => Fold a [a] Source #

O(n^2) . Fold values into a list with duplicates removed, while preserving their first occurrences

set :: Ord a => Fold a ( Set a) Source #

Fold values into a set

hashSet :: ( Eq a, Hashable a) => Fold a ( HashSet a) Source #

Fold values into a hash-set

map :: Ord a => Fold (a, b) ( Map a b) Source #

Fold pairs into a map.

foldByKeyMap :: forall k a b. Ord k => Fold a b -> Fold (k, a) ( Map k b) Source #

Given a Fold , produces a Map which applies that fold to each a separated by key k .

>>> fold (foldByKeyMap Control.Foldl.sum) [("a",1), ("b",2), ("b",20), ("a",10)]
fromList [("a",11),("b",22)]

hashMap :: ( Eq a, Hashable a) => Fold (a, b) ( HashMap a b) Source #

Fold pairs into a hash-map.

foldByKeyHashMap :: forall k a b. ( Hashable k, Eq k) => Fold a b -> Fold (k, a) ( HashMap k b) Source #

Given a Fold , produces a HashMap which applies that fold to each a separated by key k .

>>> List.sort (HashMap.toList (fold (foldByKeyHashMap Control.Foldl.sum) [("a",1), ("b",2), ("b",20), ("a",10)]))
[("a",11),("b",22)]

vector :: Vector v a => Fold a (v a) Source #

Fold all values into a vector

vectorM :: ( PrimMonad m, Vector v a) => FoldM m a (v a) Source #

Fold all values into a vector

This is more efficient than vector but is impure

Utilities

purely and impurely allow you to write folds compatible with the foldl library without incurring a foldl dependency. Write your fold to accept three parameters corresponding to the step function, initial accumulator, and extraction function and then users can upgrade your function to accept a Fold or FoldM using the purely or impurely combinators.

For example, the pipes library implements fold and foldM functions in Pipes.Prelude with the following type:

Pipes.Prelude.fold
    :: Monad m
    -> (x -> a -> x) -> x -> (x -> b) -> Producer a m () -> m b

Pipes.Prelude.foldM
    :: Monad m
    => (x -> a -> m x) -> m x -> (x -> m b) -> Producer a m () -> m b

Both fold and foldM is set up so that you can wrap them with either purely or impurely to accept a Fold or FoldM , respectively:

purely Pipes.Prelude.fold
    :: Monad m => Fold a b -> Producer a m () -> m b

impurely Pipes.Prelude.foldM
    :: Monad m => FoldM m a b -> Producer a m () -> m b

Other streaming libraries supporting purely and impurely include io-streams and streaming . So for example we have:

purely System.IO.Streams.fold_
    :: Fold a b -> Streams.InputStream a -> IO b

impurely System.IO.Streams.foldM_
    :: FoldM IO a b -> Streams.InputStream a -> IO b

The monotraversable package makes it convenient to apply a Fold or FoldM to pure containers that do not allow a general Foldable instance, like unboxed vectors:

purely ofoldlUnwrap
    :: MonoFoldable mono
    => Fold (Element mono) b -> mono -> b

impurely ofoldMUnwrap
    :: MonoFoldable mono
    => FoldM m (Element mono) b -> mono -> m b

purely :: ( forall x. (x -> a -> x) -> x -> (x -> b) -> r) -> Fold a b -> r Source #

Upgrade a fold to accept the Fold type

purely_ :: ( forall x. (x -> a -> x) -> x -> x) -> Fold a b -> b Source #

Upgrade a more traditional fold to accept the Fold type

impurely :: ( forall x. (x -> a -> m x) -> m x -> (x -> m b) -> r) -> FoldM m a b -> r Source #

Upgrade a monadic fold to accept the FoldM type

impurely_ :: Monad m => ( forall x. (x -> a -> m x) -> m x -> m x) -> FoldM m a b -> m b Source #

Upgrade a more traditional monadic fold to accept the FoldM type

generalize :: Monad m => Fold a b -> FoldM m a b Source #

Generalize a Fold to a FoldM

generalize (pure r) = pure r

generalize (f <*> x) = generalize f <*> generalize x

simplify :: FoldM Identity a b -> Fold a b Source #

Simplify a pure FoldM to a Fold

simplify (pure r) = pure r

simplify (f <*> x) = simplify f <*> simplify x

hoists :: ( forall x. m x -> n x) -> FoldM m a b -> FoldM n a b Source #

Shift a FoldM from one monad to another with a morphism such as lift or liftIO ; the effect is the same as hoist .

duplicateM :: Applicative m => FoldM m a b -> FoldM m a ( FoldM m a b) Source #

Allows to continue feeding a FoldM even after passing it to a function that closes it.

For pure Fold s, this is provided by the Comonad instance.

_Fold1 :: (a -> a -> a) -> Fold a ( Maybe a) Source #

_Fold1 step returns a new Fold using just a step function that has the same type for the accumulator and the element. The result type is the accumulator type wrapped in Maybe . The initial accumulator is retrieved from the Foldable , the result is None for empty containers.

premap :: (a -> b) -> Fold b r -> Fold a r Source #

(premap f folder) returns a new Fold where f is applied at each step

fold (premap f folder) list = fold folder (List.map f list)
>>> fold (premap Sum Foldl.mconcat) [1..10]
Sum {getSum = 55}
>>> fold Foldl.mconcat (List.map Sum [1..10])
Sum {getSum = 55}
premap id = id

premap (f . g) = premap g . premap f
premap k (pure r) = pure r

premap k (f <*> x) = premap k f <*> premap k x

premapM :: Monad m => (a -> m b) -> FoldM m b r -> FoldM m a r Source #

(premapM f folder) returns a new FoldM where f is applied to each input element

premapM return = id

premapM (f <=< g) = premap g . premap f
premapM k (pure r) = pure r

premapM k (f <*> x) = premapM k f <*> premapM k x

prefilter :: (a -> Bool ) -> Fold a r -> Fold a r Source #

(prefilter f folder) returns a new Fold where the folder's input is used only when the input satisfies a predicate f

This can also be done with handles ( handles (filtered f) ) but prefilter does not need you to depend on a lens library.

fold (prefilter p folder) list = fold folder (filter p list)
>>> fold (prefilter (>5) Control.Foldl.sum) [1..10]
40
>>> fold Control.Foldl.sum (filter (>5) [1..10])
40

prefilterM :: Monad m => (a -> m Bool ) -> FoldM m a r -> FoldM m a r Source #

(prefilterM f folder) returns a new FoldM where the folder's input is used only when the input satisfies a monadic predicate f.

predropWhile :: (a -> Bool ) -> Fold a r -> Fold a r Source #

Transforms a Fold into one which ignores elements until they stop satisfying a predicate

fold (predropWhile p folder) list = fold folder (dropWhile p list)
>>> fold (predropWhile (>5) Control.Foldl.sum) [10,9,5,9]
14

drop :: Natural -> Fold a b -> Fold a b Source #

(drop n folder) returns a new Fold that ignores the first n inputs but otherwise behaves the same as the original fold.

fold (drop n folder) list = fold folder (Data.List.genericDrop n list)
>>> Foldl.fold (Foldl.drop 3 Foldl.sum) [10, 20, 30, 1, 2, 3]
6
>>> Foldl.fold (Foldl.drop 10 Foldl.sum) [10, 20, 30, 1, 2, 3]
0

dropM :: Monad m => Natural -> FoldM m a b -> FoldM m a b Source #

(dropM n folder) returns a new FoldM that ignores the first n inputs but otherwise behaves the same as the original fold.

foldM (dropM n folder) list = foldM folder (Data.List.genericDrop n list)
>>> Foldl.foldM (Foldl.dropM 3 (Foldl.generalize Foldl.sum)) [10, 20, 30, 1, 2, 3]
6
>>> Foldl.foldM (Foldl.dropM 10 (Foldl.generalize Foldl.sum)) [10, 20, 30, 1, 2, 3]
0

type Handler a b = forall x. (b -> Const ( Dual ( Endo x)) b) -> a -> Const ( Dual ( Endo x)) a Source #

A handler for the upstream input of a Fold

Any lens, traversal, or prism will type-check as a Handler

handles :: Handler a b -> Fold b r -> Fold a r Source #

(handles t folder) transforms the input of a Fold using a lens, traversal, or prism:

handles _1       :: Fold a r -> Fold (a, b) r
handles _Left    :: Fold a r -> Fold (Either a b) r
handles traverse :: Traversable t => Fold a r -> Fold (t a) r
handles folded   :: Foldable    t => Fold a r -> Fold (t a) r
>>> fold (handles traverse sum) [[1..5],[6..10]]
55
>>> fold (handles (traverse.traverse) sum) [[Nothing, Just 2, Just 7],[Just 13, Nothing, Just 20]]
42
>>> fold (handles (filtered even) sum) [1..10]
30
>>> fold (handles _2 Foldl.mconcat) [(1,"Hello "),(2,"World"),(3,"!")]
"Hello World!"
handles id = id

handles (f . g) = handles f . handles g
handles t (pure r) = pure r

handles t (f <*> x) = handles t f <*> handles t x

foldOver :: Handler s a -> Fold a b -> s -> b Source #

(foldOver f folder xs) folds all values from a Lens, Traversal, Prism or Fold with the given folder

>>> foldOver (_Just . both) Foldl.sum (Just (2, 3))
5
>>> foldOver (_Just . both) Foldl.sum Nothing
0
Foldl.foldOver f folder xs == Foldl.fold folder (xs^..f)
Foldl.foldOver (folded.f) folder == Foldl.fold (handles f folder)
Foldl.foldOver folded == Foldl.fold

newtype EndoM m a Source #

instance Monad m => Monoid (EndoM m a) where
    mempty = EndoM return
    mappend (EndoM f) (EndoM g) = EndoM (f <=< g)

Constructors

EndoM

Fields

type HandlerM m a b = forall x. (b -> Const ( Dual ( EndoM m x)) b) -> a -> Const ( Dual ( EndoM m x)) a Source #

A Handler for the upstream input of FoldM

Any lens, traversal, or prism will type-check as a HandlerM

handlesM :: HandlerM m a b -> FoldM m b r -> FoldM m a r Source #

(handlesM t folder) transforms the input of a FoldM using a lens, traversal, or prism:

handlesM _1       :: FoldM m a r -> FoldM (a, b) r
handlesM _Left    :: FoldM m a r -> FoldM (Either a b) r
handlesM traverse :: Traversable t => FoldM m a r -> FoldM m (t a) r
handlesM folded   :: Foldable    t => FoldM m a r -> FoldM m (t a) r

handlesM obeys these laws:

handlesM id = id

handlesM (f . g) = handlesM f . handlesM g
handlesM t (pure r) = pure r

handlesM t (f <*> x) = handlesM t f <*> handlesM t x

foldOverM :: Monad m => HandlerM m s a -> FoldM m a b -> s -> m b Source #

(foldOverM f folder xs) folds all values from a Lens, Traversal, Prism or Fold monadically with the given folder

Foldl.foldOverM (folded.f) folder == Foldl.foldM (handlesM f folder)
Foldl.foldOverM folded == Foldl.foldM

folded :: ( Contravariant f, Applicative f, Foldable t) => (a -> f a) -> t a -> f (t a) Source #

folded :: Foldable t => Fold (t a) a

handles folded :: Foldable t => Fold a r -> Fold (t a) r

filtered :: Monoid m => (a -> Bool ) -> (a -> m) -> a -> m Source #

>>> fold (handles (filtered even) sum) [1..10]
30
>>> foldM (handlesM (filtered even) (Foldl.mapM_ print)) [1..10]
2
4
6
8
10

groupBy :: Ord g => (a -> g) -> Fold a r -> Fold a ( Map g r) Source #

Perform a Fold while grouping the data according to a specified group projection function. Returns the folded result grouped as a map keyed by the group.

either :: Fold a1 b1 -> Fold a2 b2 -> Fold ( Either a1 a2) (b1, b2) Source #

Combine two folds into a fold over inputs for either of them.

eitherM :: Monad m => FoldM m a1 b1 -> FoldM m a2 b2 -> FoldM m ( Either a1 a2) (b1, b2) Source #

Combine two monadic folds into a fold over inputs for either of them.

nest :: Applicative f => Fold a b -> Fold (f a) (f b) Source #

Nest a fold in an applicative.

Re-exports

Control.Monad.Primitive re-exports the PrimMonad type class

Data.Foldable re-exports the Foldable type class

Data.Vector.Generic re-exports the Vector type class

data RealWorld Source #

RealWorld is deeply magical. It is primitive , but it is not unlifted (hence ptrArg ). We never manipulate values of type RealWorld ; it's only used in the type system, to parameterise State# .

class Monad m => PrimMonad (m :: Type -> Type ) Source #

Class of monads which can perform primitive state-transformer actions.

Minimal complete definition

primitive

Instances

Instances details
PrimMonad IO
Instance details

Defined in Control.Monad.Primitive

Associated Types

type PrimState IO Source #

PrimMonad ( ST s)
Instance details

Defined in Control.Monad.Primitive

Associated Types

type PrimState ( ST s) Source #

PrimMonad ( ST s)
Instance details

Defined in Control.Monad.Primitive

Associated Types

type PrimState ( ST s) Source #

PrimMonad m => PrimMonad ( ListT m)
Instance details

Defined in Control.Monad.Primitive

Associated Types

type PrimState ( ListT m) Source #

PrimMonad m => PrimMonad ( MaybeT m)
Instance details

Defined in Control.Monad.Primitive

Associated Types

type PrimState ( MaybeT m) Source #

PrimMonad m => PrimMonad ( IdentityT m)
Instance details

Defined in Control.Monad.Primitive

Associated Types

type PrimState ( IdentityT m) Source #

( Error e, PrimMonad m) => PrimMonad ( ErrorT e m)
Instance details

Defined in Control.Monad.Primitive

Associated Types

type PrimState ( ErrorT e m) Source #

PrimMonad m => PrimMonad ( ExceptT e m)
Instance details

Defined in Control.Monad.Primitive

Associated Types

type PrimState ( ExceptT e m) Source #

PrimMonad m => PrimMonad ( ReaderT r m)
Instance details

Defined in Control.Monad.Primitive

Associated Types

type PrimState ( ReaderT r m) Source #

PrimMonad m => PrimMonad ( StateT s m)
Instance details

Defined in Control.Monad.Primitive

Associated Types

type PrimState ( StateT s m) Source #

PrimMonad m => PrimMonad ( StateT s m)
Instance details

Defined in Control.Monad.Primitive

Associated Types

type PrimState ( StateT s m) Source #

( Monoid w, PrimMonad m) => PrimMonad ( WriterT w m)
Instance details

Defined in Control.Monad.Primitive

Associated Types

type PrimState ( WriterT w m) Source #

( Monoid w, PrimMonad m) => PrimMonad ( WriterT w m)
Instance details

Defined in Control.Monad.Primitive

Associated Types

type PrimState ( WriterT w m) Source #

( Monoid w, PrimMonad m) => PrimMonad ( AccumT w m)

Since: primitive-0.6.3.0

Instance details

Defined in Control.Monad.Primitive

Associated Types

type PrimState ( AccumT w m) Source #

( Monoid w, PrimMonad m) => PrimMonad ( WriterT w m)
Instance details

Defined in Control.Monad.Primitive

Associated Types

type PrimState ( WriterT w m) Source #

PrimMonad m => PrimMonad ( SelectT r m)
Instance details

Defined in Control.Monad.Primitive

Associated Types

type PrimState ( SelectT r m) Source #

PrimMonad m => PrimMonad ( ContT r m)

Since: primitive-0.6.3.0

Instance details

Defined in Control.Monad.Primitive

Associated Types

type PrimState ( ContT r m) Source #

( Monoid w, PrimMonad m) => PrimMonad ( RWST r w s m)
Instance details

Defined in Control.Monad.Primitive

Associated Types

type PrimState ( RWST r w s m) Source #

Methods

primitive :: ( State# ( PrimState ( RWST r w s m)) -> (# State# ( PrimState ( RWST r w s m)), a #)) -> RWST r w s m a Source #

( Monoid w, PrimMonad m) => PrimMonad ( RWST r w s m)
Instance details

Defined in Control.Monad.Primitive

Associated Types

type PrimState ( RWST r w s m) Source #

Methods

primitive :: ( State# ( PrimState ( RWST r w s m)) -> (# State# ( PrimState ( RWST r w s m)), a #)) -> RWST r w s m a Source #

( Monoid w, PrimMonad m) => PrimMonad ( RWST r w s m)
Instance details

Defined in Control.Monad.Primitive

Associated Types

type PrimState ( RWST r w s m) Source #

Methods

primitive :: ( State# ( PrimState ( RWST r w s m)) -> (# State# ( PrimState ( RWST r w s m)), a #)) -> RWST r w s m a Source #

class Foldable (t :: Type -> Type ) Source #

Data structures that can be folded.

For example, given a data type

data Tree a = Empty | Leaf a | Node (Tree a) a (Tree a)

a suitable instance would be

instance Foldable Tree where
   foldMap f Empty = mempty
   foldMap f (Leaf x) = f x
   foldMap f (Node l k r) = foldMap f l `mappend` f k `mappend` foldMap f r

This is suitable even for abstract types, as the monoid is assumed to satisfy the monoid laws. Alternatively, one could define foldr :

instance Foldable Tree where
   foldr f z Empty = z
   foldr f z (Leaf x) = f x z
   foldr f z (Node l k r) = foldr f (f k (foldr f z r)) l

Foldable instances are expected to satisfy the following laws:

foldr f z t = appEndo (foldMap (Endo . f) t ) z
foldl f z t = appEndo (getDual (foldMap (Dual . Endo . flip f) t)) z
fold = foldMap id
length = getSum . foldMap (Sum . const  1)

sum , product , maximum , and minimum should all be essentially equivalent to foldMap forms, such as

sum = getSum . foldMap Sum

but may be less defined.

If the type is also a Functor instance, it should satisfy

foldMap f = fold . fmap f

which implies that

foldMap f . fmap g = foldMap (f . g)

Minimal complete definition

foldMap | foldr

Instances

Instances details
Foldable []

Since: base-2.1

Instance details

Defined in Data.Foldable

Methods

fold :: Monoid m => [m] -> m Source #

foldMap :: Monoid m => (a -> m) -> [a] -> m Source #

foldMap' :: Monoid m => (a -> m) -> [a] -> m Source #

foldr :: (a -> b -> b) -> b -> [a] -> b Source #

foldr' :: (a -> b -> b) -> b -> [a] -> b Source #

foldl :: (b -> a -> b) -> b -> [a] -> b Source #

foldl' :: (b -> a -> b) -> b -> [a] -> b Source #

foldr1 :: (a -> a -> a) -> [a] -> a Source #

foldl1 :: (a -> a -> a) -> [a] -> a Source #

toList :: [a] -> [a] Source #

null :: [a] -> Bool Source #

length :: [a] -> Int Source #

elem :: Eq a => a -> [a] -> Bool Source #

maximum :: Ord a => [a] -> a Source #

minimum :: Ord a => [a] -> a Source #

sum :: Num a => [a] -> a Source #

product :: Num a => [a] -> a Source #

Foldable Maybe

Since: base-2.1

Instance details

Defined in Data.Foldable

Foldable Par1

Since: base-4.9.0.0

Instance details

Defined in Data.Foldable

Foldable Complex

Since: base-4.9.0.0

Instance details

Defined in Data.Complex

Foldable Min

Since: base-4.9.0.0

Instance details

Defined in Data.Semigroup

Foldable Max

Since: base-4.9.0.0

Instance details

Defined in Data.Semigroup

Foldable First

Since: base-4.9.0.0

Instance details

Defined in Data.Semigroup

Foldable Last

Since: base-4.9.0.0

Instance details

Defined in Data.Semigroup

Foldable Option

Since: base-4.9.0.0

Instance details

Defined in Data.Semigroup

Foldable ZipList

Since: base-4.9.0.0

Instance details

Defined in Control.Applicative

Foldable Identity

Since: base-4.8.0.0

Instance details

Defined in Data.Functor.Identity

Foldable First

Since: base-4.8.0.0

Instance details

Defined in Data.Foldable

Foldable Last

Since: base-4.8.0.0

Instance details

Defined in Data.Foldable

Foldable Dual

Since: base-4.8.0.0

Instance details

Defined in Data.Foldable

Foldable Sum

Since: base-4.8.0.0

Instance details

Defined in Data.Foldable

Foldable Product

Since: base-4.8.0.0

Instance details

Defined in Data.Foldable

Foldable Down

Since: base-4.12.0.0

Instance details

Defined in Data.Foldable

Foldable NonEmpty

Since: base-4.9.0.0

Instance details

Defined in Data.Foldable

Foldable IntMap

Folds in order of increasing key.

Instance details

Defined in Data.IntMap.Internal

Foldable Tree
Instance details

Defined in Data.Tree

Foldable Seq
Instance details

Defined in Data.Sequence.Internal

Foldable FingerTree
Instance details

Defined in Data.Sequence.Internal

Foldable Digit
Instance details

Defined in Data.Sequence.Internal

Foldable Node
Instance details

Defined in Data.Sequence.Internal

Foldable Elem
Instance details

Defined in Data.Sequence.Internal

Foldable ViewL
Instance details

Defined in Data.Sequence.Internal

Foldable ViewR
Instance details

Defined in Data.Sequence.Internal

Foldable Set

Folds in order of increasing key.

Instance details

Defined in Data.Set.Internal

Foldable Hashed
Instance details

Defined in Data.Hashable.Class

Foldable HashSet
Instance details

Defined in Data.HashSet.Internal

Foldable ( Either a)

Since: base-4.7.0.0

Instance details

Defined in Data.Foldable

Methods

fold :: Monoid m => Either a m -> m Source #

foldMap :: Monoid m => (a0 -> m) -> Either a a0 -> m Source #

foldMap' :: Monoid m => (a0 -> m) -> Either a a0 -> m Source #

foldr :: (a0 -> b -> b) -> b -> Either a a0 -> b Source #

foldr' :: (a0 -> b -> b) -> b -> Either a a0 -> b Source #

foldl :: (b -> a0 -> b) -> b -> Either a a0 -> b Source #

foldl' :: (b -> a0 -> b) -> b -> Either a a0 -> b Source #

foldr1 :: (a0 -> a0 -> a0) -> Either a a0 -> a0 Source #

foldl1 :: (a0 -> a0 -> a0) -> Either a a0 -> a0 Source #

toList :: Either a a0 -> [a0] Source #

null :: Either a a0 -> Bool Source #

length :: Either a a0 -> Int Source #

elem :: Eq a0 => a0 -> Either a a0 -> Bool Source #

maximum :: Ord a0 => Either a a0 -> a0 Source #

minimum :: Ord a0 => Either a a0 -> a0 Source #

sum :: Num a0 => Either a a0 -> a0 Source #

product :: Num a0 => Either a a0 -> a0 Source #

Foldable ( V1 :: Type -> Type )

Since: base-4.9.0.0

Instance details

Defined in Data.Foldable

Foldable ( U1 :: Type -> Type )

Since: base-4.9.0.0

Instance details

Defined in Data.Foldable

Foldable ( UAddr :: Type -> Type )

Since: base-4.9.0.0

Instance details

Defined in Data.Foldable

Foldable ( UChar :: Type -> Type )

Since: base-4.9.0.0

Instance details

Defined in Data.Foldable

Foldable ( UDouble :: Type -> Type )

Since: base-4.9.0.0

Instance details

Defined in Data.Foldable

Foldable ( UFloat :: Type -> Type )

Since: base-4.9.0.0

Instance details

Defined in Data.Foldable

Foldable ( UInt :: Type -> Type )

Since: base-4.9.0.0

Instance details

Defined in Data.Foldable

Foldable ( UWord :: Type -> Type )

Since: base-4.9.0.0

Instance details

Defined in Data.Foldable

Foldable ( (,) a)

Since: base-4.7.0.0

Instance details

Defined in Data.Foldable

Methods

fold :: Monoid m => (a, m) -> m Source #

foldMap :: Monoid m => (a0 -> m) -> (a, a0) -> m Source #

foldMap' :: Monoid m => (a0 -> m) -> (a, a0) -> m Source #

foldr :: (a0 -> b -> b) -> b -> (a, a0) -> b Source #

foldr' :: (a0 -> b -> b) -> b -> (a, a0) -> b Source #

foldl :: (b -> a0 -> b) -> b -> (a, a0) -> b Source #

foldl' :: (b -> a0 -> b) -> b -> (a, a0) -> b Source #

foldr1 :: (a0 -> a0 -> a0) -> (a, a0) -> a0 Source #

foldl1 :: (a0 -> a0 -> a0) -> (a, a0) -> a0 Source #

toList :: (a, a0) -> [a0] Source #

null :: (a, a0) -> Bool Source #

length :: (a, a0) -> Int Source #

elem :: Eq a0 => a0 -> (a, a0) -> Bool Source #

maximum :: Ord a0 => (a, a0) -> a0 Source #

minimum :: Ord a0 => (a, a0) -> a0 Source #

sum :: Num a0 => (a, a0) -> a0 Source #

product :: Num a0 => (a, a0) -> a0 Source #

Foldable ( Array i)

Since: base-4.8.0.0

Instance details

Defined in Data.Foldable

Foldable ( Arg a)

Since: base-4.9.0.0

Instance details

Defined in Data.Semigroup

Methods

fold :: Monoid m => Arg a m -> m Source #

foldMap :: Monoid m => (a0 -> m) -> Arg a a0 -> m Source #

foldMap' :: Monoid m => (a0 -> m) -> Arg a a0 -> m Source #

foldr :: (a0 -> b -> b) -> b -> Arg a a0 -> b Source #

foldr' :: (a0 -> b -> b) -> b -> Arg a a0 -> b Source #

foldl :: (b -> a0 -> b) -> b -> Arg a a0 -> b Source #

foldl' :: (b -> a0 -> b) -> b -> Arg a a0 -> b Source #

foldr1 :: (a0 -> a0 -> a0) -> Arg a a0 -> a0 Source #

foldl1 :: (a0 -> a0 -> a0) -> Arg a a0 -> a0 Source #

toList :: Arg a a0 -> [a0] Source #

null :: Arg a a0 -> Bool Source #

length :: Arg a a0 -> Int Source #

elem :: Eq a0 => a0 -> Arg a a0 -> Bool Source #

maximum :: Ord a0 => Arg a a0 -> a0 Source #

minimum :: Ord a0 => Arg a a0 -> a0 Source #

sum :: Num a0 => Arg a a0 -> a0 Source #

product :: Num a0 => Arg a a0 -> a0 Source #

Foldable ( Proxy :: Type -> Type )

Since: base-4.7.0.0

Instance details

Defined in Data.Foldable

Foldable ( Map k)

Folds in order of increasing key.

Instance details

Defined in Data.Map.Internal

Methods

fold :: Monoid m => Map k m -> m Source #

foldMap :: Monoid m => (a -> m) -> Map k a -> m Source #

foldMap' :: Monoid m => (a -> m) -> Map k a -> m Source #

foldr :: (a -> b -> b) -> b -> Map k a -> b Source #

foldr' :: (a -> b -> b) -> b -> Map k a -> b Source #

foldl :: (b -> a -> b) -> b -> Map k a -> b Source #

foldl' :: (b -> a -> b) -> b -> Map k a -> b Source #

foldr1 :: (a -> a -> a) -> Map k a -> a Source #

foldl1 :: (a -> a -> a) -> Map k a -> a Source #

toList :: Map k a -> [a] Source #

null :: Map k a -> Bool Source #

length :: Map k a -> Int Source #

elem :: Eq a => a -> Map k a -> Bool Source #

maximum :: Ord a => Map k a -> a Source #

minimum :: Ord a => Map k a -> a Source #

sum :: Num a => Map k a -> a Source #

product :: Num a => Map k a -> a Source #

Foldable f => Foldable ( ListT f)
Instance details

Defined in Control.Monad.Trans.List

Foldable f => Foldable ( Lift f)
Instance details

Defined in Control.Applicative.Lift

Foldable f => Foldable ( MaybeT f)
Instance details

Defined in Control.Monad.Trans.Maybe

Foldable ( HashMap k)
Instance details

Defined in Data.HashMap.Internal

Foldable f => Foldable ( Rec1 f)

Since: base-4.9.0.0

Instance details

Defined in Data.Foldable

Foldable ( Const m :: Type -> Type )

Since: base-4.7.0.0

Instance details

Defined in Data.Functor.Const

Foldable f => Foldable ( Ap f)

Since: base-4.12.0.0

Instance details

Defined in Data.Foldable

Methods

fold :: Monoid m => Ap f m -> m Source #

foldMap :: Monoid m => (a -> m) -> Ap f a -> m Source #

foldMap' :: Monoid m => (a -> m) -> Ap f a -> m Source #

foldr :: (a -> b -> b) -> b -> Ap f a -> b Source #

foldr' :: (a -> b -> b) -> b -> Ap f a -> b Source #

foldl :: (b -> a -> b) -> b -> Ap f a -> b Source #

foldl' :: (b -> a -> b) -> b -> Ap f a -> b Source #

foldr1 :: (a -> a -> a) -> Ap f a -> a Source #

foldl1 :: (a -> a -> a) -> Ap f a -> a Source #

toList :: Ap f a -> [a] Source #

null :: Ap f a -> Bool Source #

length :: Ap f a -> Int Source #

elem :: Eq a => a -> Ap f a -> Bool Source #

maximum :: Ord a => Ap f a -> a Source #

minimum :: Ord a => Ap f a -> a Source #

sum :: Num a => Ap f a -> a Source #

product :: Num a => Ap f a -> a Source #

Foldable f => Foldable ( Alt f)

Since: base-4.12.0.0

Instance details

Defined in Data.Foldable

Methods

fold :: Monoid m => Alt f m -> m Source #

foldMap :: Monoid m => (a -> m) -> Alt f a -> m Source #

foldMap' :: Monoid m => (a -> m) -> Alt f a -> m Source #

foldr :: (a -> b -> b) -> b -> Alt f a -> b Source #

foldr' :: (a -> b -> b) -> b -> Alt f a -> b Source #

foldl :: (b -> a -> b) -> b -> Alt f a -> b Source #

foldl' :: (b -> a -> b) -> b -> Alt f a -> b Source #

foldr1 :: (a -> a -> a) -> Alt f a -> a Source #

foldl1 :: (a -> a -> a) -> Alt f a -> a Source #

toList :: Alt f a -> [a] Source #

null :: Alt f a -> Bool Source #

length :: Alt f a -> Int Source #

elem :: Eq a => a -> Alt f a -> Bool Source #

maximum :: Ord a => Alt f a -> a Source #

minimum :: Ord a => Alt f a -> a Source #

sum :: Num a => Alt f a -> a Source #

product :: Num a => Alt f a -> a Source #

Bifoldable p => Foldable ( Join p)
Instance details

Defined in Data.Bifunctor.Join

Foldable f => Foldable ( IdentityT f)
Instance details

Defined in Control.Monad.Trans.Identity

Foldable f => Foldable ( ErrorT e f)
Instance details

Defined in Control.Monad.Trans.Error

Methods

fold :: Monoid m => ErrorT e f m -> m Source #

foldMap :: Monoid m => (a -> m) -> ErrorT e f a -> m Source #

foldMap' :: Monoid m => (a -> m) -> ErrorT e f a -> m Source #

foldr :: (a -> b -> b) -> b -> ErrorT e f a -> b Source #

foldr' :: (a -> b -> b) -> b -> ErrorT e f a -> b Source #

foldl :: (b -> a -> b) -> b -> ErrorT e f a -> b Source #

foldl' :: (b -> a -> b) -> b -> ErrorT e f a -> b Source #

foldr1 :: (a -> a -> a) -> ErrorT e f a -> a Source #

foldl1 :: (a -> a -> a) -> ErrorT e f a -> a Source #

toList :: ErrorT e f a -> [a] Source #

null :: ErrorT e f a -> Bool Source #

length :: ErrorT e f a -> Int Source #

elem :: Eq a => a -> ErrorT e f a -> Bool Source #

maximum :: Ord a => ErrorT e f a -> a Source #

minimum :: Ord a => ErrorT e f a -> a Source #

sum :: Num a => ErrorT e f a -> a Source #

product :: Num a => ErrorT e f a -> a Source #

Foldable f => Foldable ( ExceptT e f)
Instance details

Defined in Control.Monad.Trans.Except

Foldable f => Foldable ( WriterT w f)
Instance details

Defined in Control.Monad.Trans.Writer.Lazy

Foldable f => Foldable ( WriterT w f)
Instance details

Defined in Control.Monad.Trans.Writer.Strict

Foldable ( Tagged s)
Instance details

Defined in Data.Tagged

Foldable f => Foldable ( Reverse f)

Fold from right to left.

Instance details

Defined in Data.Functor.Reverse

Foldable f => Foldable ( Backwards f)

Derived instance.

Instance details

Defined in Control.Applicative.Backwards

Foldable ( K1 i c :: Type -> Type )

Since: base-4.9.0.0

Instance details

Defined in Data.Foldable

Methods

fold :: Monoid m => K1 i c m -> m Source #

foldMap :: Monoid m => (a -> m) -> K1 i c a -> m Source #

foldMap' :: Monoid m => (a -> m) -> K1 i c a -> m Source #

foldr :: (a -> b -> b) -> b -> K1 i c a -> b Source #

foldr' :: (a -> b -> b) -> b -> K1 i c a -> b Source #

foldl :: (b -> a -> b) -> b -> K1 i c a -> b Source #

foldl' :: (b -> a -> b) -> b -> K1 i c a -> b Source #

foldr1 :: (a -> a -> a) -> K1 i c a -> a Source #

foldl1 :: (a -> a -> a) -> K1 i c a -> a Source #

toList :: K1 i c a -> [a] Source #

null :: K1 i c a -> Bool Source #

length :: K1 i c a -> Int Source #

elem :: Eq a => a -> K1 i c a -> Bool Source #

maximum :: Ord a => K1 i c a -> a Source #

minimum :: Ord a => K1 i c a -> a Source #

sum :: Num a => K1 i c a -> a Source #

product :: Num a => K1 i c a -> a Source #

( Foldable f, Foldable g) => Foldable (f :+: g)

Since: base-4.9.0.0

Instance details

Defined in Data.Foldable

Methods

fold :: Monoid m => (f :+: g) m -> m Source #

foldMap :: Monoid m => (a -> m) -> (f :+: g) a -> m Source #

foldMap' :: Monoid m => (a -> m) -> (f :+: g) a -> m Source #

foldr :: (a -> b -> b) -> b -> (f :+: g) a -> b Source #

foldr' :: (a -> b -> b) -> b -> (f :+: g) a -> b Source #

foldl :: (b -> a -> b) -> b -> (f :+: g) a -> b Source #

foldl' :: (b -> a -> b) -> b -> (f :+: g) a -> b Source #

foldr1 :: (a -> a -> a) -> (f :+: g) a -> a Source #

foldl1 :: (a -> a -> a) -> (f :+: g) a -> a Source #

toList :: (f :+: g) a -> [a] Source #

null :: (f :+: g) a -> Bool Source #

length :: (f :+: g) a -> Int Source #

elem :: Eq a => a -> (f :+: g) a -> Bool Source #

maximum :: Ord a => (f :+: g) a -> a Source #

minimum :: Ord a => (f :+: g) a -> a Source #

sum :: Num a => (f :+: g) a -> a Source #

product :: Num a => (f :+: g) a -> a Source #

( Foldable f, Foldable g) => Foldable (f :*: g)

Since: base-4.9.0.0

Instance details

Defined in Data.Foldable

Methods

fold :: Monoid m => (f :*: g) m -> m Source #

foldMap :: Monoid m => (a -> m) -> (f :*: g) a -> m Source #

foldMap' :: Monoid m => (a -> m) -> (f :*: g) a -> m Source #

foldr :: (a -> b -> b) -> b -> (f :*: g) a -> b Source #

foldr' :: (a -> b -> b) -> b -> (f :*: g) a -> b Source #

foldl :: (b -> a -> b) -> b -> (f :*: g) a -> b Source #

foldl' :: (b -> a -> b) -> b -> (f :*: g) a -> b Source #

foldr1 :: (a -> a -> a) -> (f :*: g) a -> a Source #

foldl1 :: (a -> a -> a) -> (f :*: g) a -> a Source #

toList :: (f :*: g) a -> [a] Source #

null :: (f :*: g) a -> Bool Source #

length :: (f :*: g) a -> Int Source #

elem :: Eq a => a -> (f :*: g) a -> Bool Source #

maximum :: Ord a => (f :*: g) a -> a Source #

minimum :: Ord a => (f :*: g) a -> a Source #

sum :: Num a => (f :*: g) a -> a Source #

product :: Num a => (f :*: g) a -> a Source #

( Foldable f, Foldable g) => Foldable ( Product f g)

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Product

( Foldable f, Foldable g) => Foldable ( Sum f g)

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Sum

Methods

fold :: Monoid m => Sum f g m -> m Source #

foldMap :: Monoid m => (a -> m) -> Sum f g a -> m Source #

foldMap' :: Monoid m => (a -> m) -> Sum f g a -> m Source #

foldr :: (a -> b -> b) -> b -> Sum f g a -> b Source #

foldr' :: (a -> b -> b) -> b -> Sum f g a -> b Source #

foldl :: (b -> a -> b) -> b -> Sum f g a -> b Source #

foldl' :: (b -> a -> b) -> b -> Sum f g a -> b Source #

foldr1 :: (a -> a -> a) -> Sum f g a -> a Source #

foldl1 :: (a -> a -> a) -> Sum f g a -> a Source #

toList :: Sum f g a -> [a] Source #

null :: Sum f g a -> Bool Source #

length :: Sum f g a -> Int Source #

elem :: Eq a => a -> Sum f g a -> Bool Source #

maximum :: Ord a => Sum f g a -> a Source #

minimum :: Ord a => Sum f g a -> a Source #

sum :: Num a => Sum f g a -> a Source #

product :: Num a => Sum f g a -> a Source #

Foldable ( Forget r a :: Type -> Type )
Instance details

Defined in Data.Profunctor.Types

Methods

fold :: Monoid m => Forget r a m -> m Source #

foldMap :: Monoid m => (a0 -> m) -> Forget r a a0 -> m Source #

foldMap' :: Monoid m => (a0 -> m) -> Forget r a a0 -> m Source #

foldr :: (a0 -> b -> b) -> b -> Forget r a a0 -> b Source #

foldr' :: (a0 -> b -> b) -> b -> Forget r a a0 -> b Source #

foldl :: (b -> a0 -> b) -> b -> Forget r a a0 -> b Source #

foldl' :: (b -> a0 -> b) -> b -> Forget r a a0 -> b Source #

foldr1 :: (a0 -> a0 -> a0) -> Forget r a a0 -> a0 Source #

foldl1 :: (a0 -> a0 -> a0) -> Forget r a a0 -> a0 Source #

toList :: Forget r a a0 -> [a0] Source #

null :: Forget r a a0 -> Bool Source #

length :: Forget r a a0 -> Int Source #

elem :: Eq a0 => a0 -> Forget r a a0 -> Bool Source #

maximum :: Ord a0 => Forget r a a0 -> a0 Source #

minimum :: Ord a0 => Forget r a a0 -> a0 Source #

sum :: Num a0 => Forget r a a0 -> a0 Source #

product :: Num a0 => Forget r a a0 -> a0 Source #

Foldable f => Foldable ( M1 i c f)

Since: base-4.9.0.0

Instance details

Defined in Data.Foldable

Methods

fold :: Monoid m => M1 i c f m -> m Source #

foldMap :: Monoid m => (a -> m) -> M1 i c f a -> m Source #

foldMap' :: Monoid m => (a -> m) -> M1 i c f a -> m Source #

foldr :: (a -> b -> b) -> b -> M1 i c f a -> b Source #

foldr' :: (a -> b -> b) -> b -> M1 i c f a -> b Source #

foldl :: (b -> a -> b) -> b -> M1 i c f a -> b Source #

foldl' :: (b -> a -> b) -> b -> M1 i c f a -> b Source #

foldr1 :: (a -> a -> a) -> M1 i c f a -> a Source #

foldl1 :: (a -> a -> a) -> M1 i c f a -> a Source #

toList :: M1 i c f a -> [a] Source #

null :: M1 i c f a -> Bool Source #

length :: M1 i c f a -> Int Source #

elem :: Eq a => a -> M1 i c f a -> Bool Source #

maximum :: Ord a => M1 i c f a -> a Source #

minimum :: Ord a => M1 i c f a -> a Source #

sum :: Num a => M1 i c f a -> a Source #

product :: Num a => M1 i c f a -> a Source #

( Foldable f, Foldable g) => Foldable (f :.: g)

Since: base-4.9.0.0

Instance details

Defined in Data.Foldable

Methods

fold :: Monoid m => (f :.: g) m -> m Source #

foldMap :: Monoid m => (a -> m) -> (f :.: g) a -> m Source #

foldMap' :: Monoid m => (a -> m) -> (f :.: g) a -> m Source #

foldr :: (a -> b -> b) -> b -> (f :.: g) a -> b Source #

foldr' :: (a -> b -> b) -> b -> (f :.: g) a -> b Source #

foldl :: (b -> a -> b) -> b -> (f :.: g) a -> b Source #

foldl' :: (b -> a -> b) -> b -> (f :.: g) a -> b Source #

foldr1 :: (a -> a -> a) -> (f :.: g) a -> a Source #

foldl1 :: (a -> a -> a) -> (f :.: g) a -> a Source #

toList :: (f :.: g) a -> [a] Source #

null :: (f :.: g) a -> Bool Source #

length :: (f :.: g) a -> Int Source #

elem :: Eq a => a -> (f :.: g) a -> Bool Source #

maximum :: Ord a => (f :.: g) a -> a Source #

minimum :: Ord a => (f :.: g) a -> a Source #

sum :: Num a => (f :.: g) a -> a Source #

product :: Num a => (f :.: g) a -> a Source #

( Foldable f, Foldable g) => Foldable ( Compose f g)

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Compose

Bifoldable p => Foldable ( WrappedBifunctor p a)
Instance details

Defined in Data.Bifunctor.Wrapped

Foldable g => Foldable ( Joker g a)
Instance details

Defined in Data.Bifunctor.Joker

Methods

fold :: Monoid m => Joker g a m -> m Source #

foldMap :: Monoid m => (a0 -> m) -> Joker g a a0 -> m Source #

foldMap' :: Monoid m => (a0 -> m) -> Joker g a a0 -> m Source #

foldr :: (a0 -> b -> b) -> b -> Joker g a a0 -> b Source #

foldr' :: (a0 -> b -> b) -> b -> Joker g a a0 -> b Source #

foldl :: (b -> a0 -> b) -> b -> Joker g a a0 -> b Source #

foldl' :: (b -> a0 -> b) -> b -> Joker g a a0 -> b Source #

foldr1 :: (a0 -> a0 -> a0) -> Joker g a a0 -> a0 Source #

foldl1 :: (a0 -> a0 -> a0) -> Joker g a a0 -> a0 Source #

toList :: Joker g a a0 -> [a0] Source #

null :: Joker g a a0 -> Bool Source #

length :: Joker g a a0 -> Int Source #

elem :: Eq a0 => a0 -> Joker g a a0 -> Bool Source #

maximum :: Ord a0 => Joker g a a0 -> a0 Source #

minimum :: Ord a0 => Joker g a a0 -> a0 Source #

sum :: Num a0 => Joker g a a0 -> a0 Source #

product :: Num a0 => Joker g a a0 -> a0 Source #

Bifoldable p => Foldable ( Flip p a)
Instance details

Defined in Data.Bifunctor.Flip

Methods

fold :: Monoid m => Flip p a m -> m Source #

foldMap :: Monoid m => (a0 -> m) -> Flip p a a0 -> m Source #

foldMap' :: Monoid m => (a0 -> m) -> Flip p a a0 -> m Source #

foldr :: (a0 -> b -> b) -> b -> Flip p a a0 -> b Source #

foldr' :: (a0 -> b -> b) -> b -> Flip p a a0 -> b Source #

foldl :: (b -> a0 -> b) -> b -> Flip p a a0 -> b Source #

foldl' :: (b -> a0 -> b) -> b -> Flip p a a0 -> b Source #

foldr1 :: (a0 -> a0 -> a0) -> Flip p a a0 -> a0 Source #

foldl1 :: (a0 -> a0 -> a0) -> Flip p a a0 -> a0 Source #

toList :: Flip p a a0 -> [a0] Source #

null :: Flip p a a0 -> Bool Source #

length :: Flip p a a0 -> Int Source #

elem :: Eq a0 => a0 -> Flip p a a0 -> Bool Source #

maximum :: Ord a0 => Flip p a a0 -> a0 Source #

minimum :: Ord a0 => Flip p a a0 -> a0 Source #

sum :: Num a0 => Flip p a a0 -> a0 Source #

product :: Num a0 => Flip p a a0 -> a0 Source #

Foldable ( Clown f a :: Type -> Type )
Instance details

Defined in Data.Bifunctor.Clown

Methods

fold :: Monoid m => Clown f a m -> m Source #

foldMap :: Monoid m => (a0 -> m) -> Clown f a a0 -> m Source #

foldMap' :: Monoid m => (a0 -> m) -> Clown f a a0 -> m Source #

foldr :: (a0 -> b -> b) -> b -> Clown f a a0 -> b Source #

foldr' :: (a0 -> b -> b) -> b -> Clown f a a0 -> b Source #

foldl :: (b -> a0 -> b) -> b -> Clown f a a0 -> b Source #

foldl' :: (b -> a0 -> b) -> b -> Clown f a a0 -> b Source #

foldr1 :: (a0 -> a0 -> a0) -> Clown f a a0 -> a0 Source #

foldl1 :: (a0 -> a0 -> a0) -> Clown f a a0 -> a0 Source #

toList :: Clown f a a0 -> [a0] Source #

null :: Clown f a a0 -> Bool Source #

length :: Clown f a a0 -> Int Source #

elem :: Eq a0 => a0 -> Clown f a a0 -> Bool Source #

maximum :: Ord a0 => Clown f a a0 -> a0 Source #

minimum :: Ord a0 => Clown f a a0 -> a0 Source #

sum :: Num a0 => Clown f a a0 -> a0 Source #

product :: Num a0 => Clown f a a0 -> a0 Source #

( Foldable (f a), Foldable (g a)) => Foldable ( Sum f g a)
Instance details

Defined in Data.Bifunctor.Sum

Methods

fold :: Monoid m => Sum f g a m -> m Source #

foldMap :: Monoid m => (a0 -> m) -> Sum f g a a0 -> m Source #

foldMap' :: Monoid m => (a0 -> m) -> Sum f g a a0 -> m Source #

foldr :: (a0 -> b -> b) -> b -> Sum f g a a0 -> b Source #

foldr' :: (a0 -> b -> b) -> b -> Sum f g a a0 -> b Source #

foldl :: (b -> a0 -> b) -> b -> Sum f g a a0 -> b Source #

foldl' :: (b -> a0 -> b) -> b -> Sum f g a a0 -> b Source #

foldr1 :: (a0 -> a0 -> a0) -> Sum f g a a0 -> a0 Source #

foldl1 :: (a0 -> a0 -> a0) -> Sum f g a a0 -> a0 Source #

toList :: Sum f g a a0 -> [a0] Source #

null :: Sum f g a a0 -> Bool Source #

length :: Sum f g a a0 -> Int Source #

elem :: Eq a0 => a0 -> Sum f g a a0 -> Bool Source #

maximum :: Ord a0 => Sum f g a a0 -> a0 Source #

minimum :: Ord a0 => Sum f g a a0 -> a0 Source #

sum :: Num a0 => Sum f g a a0 -> a0 Source #

product :: Num a0 => Sum f g a a0 -> a0 Source #

( Foldable (f a), Foldable (g a)) => Foldable ( Product f g a)
Instance details

Defined in Data.Bifunctor.Product

Methods

fold :: Monoid m => Product f g a m -> m Source #

foldMap :: Monoid m => (a0 -> m) -> Product f g a a0 -> m Source #

foldMap' :: Monoid m => (a0 -> m) -> Product f g a a0 -> m Source #

foldr :: (a0 -> b -> b) -> b -> Product f g a a0 -> b Source #

foldr' :: (a0 -> b -> b) -> b -> Product f g a a0 -> b Source #

foldl :: (b -> a0 -> b) -> b -> Product f g a a0 -> b Source #

foldl' :: (b -> a0 -> b) -> b -> Product f g a a0 -> b Source #

foldr1 :: (a0 -> a0 -> a0) -> Product f g a a0 -> a0 Source #

foldl1 :: (a0 -> a0 -> a0) -> Product f g a a0 -> a0 Source #

toList :: Product f g a a0 -> [a0] Source #

null :: Product f g a a0 -> Bool Source #

length :: Product f g a a0 -> Int Source #

elem :: Eq a0 => a0 -> Product f g a a0 -> Bool Source #

maximum :: Ord a0 => Product f g a a0 -> a0 Source #

minimum :: Ord a0 => Product f g a a0 -> a0 Source #

sum :: Num a0 => Product f g a a0 -> a0 Source #

product :: Num a0 => Product f g a a0 -> a0 Source #

( Foldable f, Bifoldable p) => Foldable ( Tannen f p a)
Instance details

Defined in Data.Bifunctor.Tannen

Methods

fold :: Monoid m => Tannen f p a m -> m Source #

foldMap :: Monoid m => (a0 -> m) -> Tannen f p a a0 -> m Source #

foldMap' :: Monoid m => (a0 -> m) -> Tannen f p a a0 -> m Source #

foldr :: (a0 -> b -> b) -> b -> Tannen f p a a0 -> b Source #

foldr' :: (a0 -> b -> b) -> b -> Tannen f p a a0 -> b Source #

foldl :: (b -> a0 -> b) -> b -> Tannen f p a a0 -> b Source #

foldl' :: (b -> a0 -> b) -> b -> Tannen f p a a0 -> b Source #

foldr1 :: (a0 -> a0 -> a0) -> Tannen f p a a0 -> a0 Source #

foldl1 :: (a0 -> a0 -> a0) -> Tannen f p a a0 -> a0 Source #

toList :: Tannen f p a a0 -> [a0] Source #

null :: Tannen f p a a0 -> Bool Source #

length :: Tannen f p a a0 -> Int Source #

elem :: Eq a0 => a0 -> Tannen f p a a0 -> Bool Source #

maximum :: Ord a0 => Tannen f p a a0 -> a0 Source #

minimum :: Ord a0 => Tannen f p a a0 -> a0 Source #

sum :: Num a0 => Tannen f p a a0 -> a0 Source #

product :: Num a0 => Tannen f p a a0 -> a0 Source #

( Bifoldable p, Foldable g) => Foldable ( Biff p f g a)
Instance details

Defined in Data.Bifunctor.Biff

Methods

fold :: Monoid m => Biff p f g a m -> m Source #

foldMap :: Monoid m => (a0 -> m) -> Biff p f g a a0 -> m Source #

foldMap' :: Monoid m => (a0 -> m) -> Biff p f g a a0 -> m Source #

foldr :: (a0 -> b -> b) -> b -> Biff p f g a a0 -> b Source #

foldr' :: (a0 -> b -> b) -> b -> Biff p f g a a0 -> b Source #

foldl :: (b -> a0 -> b) -> b -> Biff p f g a a0 -> b Source #

foldl' :: (b -> a0 -> b) -> b -> Biff p f g a a0 -> b Source #

foldr1 :: (a0 -> a0 -> a0) -> Biff p f g a a0 -> a0 Source #

foldl1 :: (a0 -> a0 -> a0) -> Biff p f g a a0 -> a0 Source #

toList :: Biff p f g a a0 -> [a0] Source #

null :: Biff p f g a a0 -> Bool Source #

length :: Biff p f g a a0 -> Int Source #

elem :: Eq a0 => a0 -> Biff p f g a a0 -> Bool Source #

maximum :: Ord a0 => Biff p f g a a0 -> a0 Source #

minimum :: Ord a0 => Biff p f g a a0 -> a0 Source #

sum :: Num a0 => Biff p f g a a0 -> a0 Source #

product :: Num a0 => Biff p f g a a0 -> a0 Source #

type family Mutable (v :: Type -> Type ) = (mv :: Type -> Type -> Type ) | mv -> v Source #

Mutable v s a is the mutable version of the pure vector type v a with the state token s . It is injective on GHC 8 and newer.

class MVector ( Mutable v) a => Vector (v :: Type -> Type ) a Source #

Class of immutable vectors. Every immutable vector is associated with its mutable version through the Mutable type family. Methods of this class should not be used directly. Instead, Data.Vector.Generic and other Data.Vector modules provide safe and fusible wrappers.

Minimum complete implementation: