Module

Control.Fold

Package
purescript-folds
Repository
paf31/purescript-folds

This module provides a type Fold for lefts folds, which can be combined using the Applicative class:

average :: Fold Number Number
average = (/) <$> sum <*> length

Fold can be used to fold a Foldable structure (foldl), or scan a Traversable structure (scanl):

finalAverage = foldl average [1.0, 2.0, 3.0] :: Number
movingAverage = scanl average [1.0, 2.0, 3.0] :: Array Number

This library is based on the foldl library by Gabriel Gonzalez: http://hackage.haskell.org/package/foldl

#Fold Source

newtype Fold a b

A left fold, which takes zero or more values of type a as input and produces output of type b.

Instances

#stepFold Source

stepFold :: forall b a. a -> Fold a b -> Fold a b

Step a fold by providing a single input.

#unfoldFold Source

unfoldFold :: forall b a s. s -> (s -> a -> s) -> (s -> b) -> Fold a b

Create a Fold by providing an initial state, a function which updates that state, and a function which produces output from a state.

#unfoldFold_ Source

unfoldFold_ :: forall b a. b -> (b -> a -> b) -> Fold a b

Create a Fold by providing an initial state and a function which updates that state. This is a variant of unfoldFold where the output is the state itself.

#foldl Source

foldl :: forall b a f. Foldable f => Fold a b -> f a -> b

Run a Fold by providing a Foldable container of inputs, and then generating a single output. This is analogous to the foldl function from Data.Foldable.

#scanl Source

scanl :: forall b a f. Traversable f => Fold a b -> f a -> f b

Run a Fold by providing a Traversable container of inputs, and generating an output for each input. This is analogous to the scanl function from Data.Traversable.

#mconcat Source

mconcat :: forall m. Monoid m => Fold m m

Fold values in some Monoid.

#head Source

head :: forall a. Fold a (Maybe a)

A Fold which remembers the first input.

#last Source

last :: forall a. Fold a (Maybe a)

A Fold which keeps the last input.

#null Source

null :: forall a. Fold a Boolean

A Fold which tests whether any inputs were seen.

#length Source

length :: forall s a. Semiring s => Fold a s

A Fold which counts its inputs.

#and Source

and :: forall b. HeytingAlgebra b => Fold b b

A Fold which tests if all of its inputs were true (generalized to work with an arbitrary HeytingAlgebra).

#or Source

or :: forall b. HeytingAlgebra b => Fold b b

A Fold which tests if any of its inputs were true (generalized to work with an arbitrary HeytingAlgebra).

#any Source

any :: forall b a. HeytingAlgebra b => (a -> b) -> Fold a b

A Fold which tests if any of its inputs satisfy some predicate (generalized to work with an arbitrary HeytingAlgebra).

#all Source

all :: forall b a. HeytingAlgebra b => (a -> b) -> Fold a b

A Fold which tests if all of its inputs satisfy some predicate (generalized to work with an arbitrary HeytingAlgebra).

#sum Source

sum :: forall s. Semiring s => Fold s s

A Fold which computes the sum of its inputs (generalized to work with an arbitrary Semiring).

#product Source

product :: forall s. Semiring s => Fold s s

A Fold which computes the product of its inputs (generalized to work with an arbitrary Semiring).

#maximum Source

maximum :: forall a. Bounded a => Fold a a

A Fold which computes the maximum of its inputs (generalized to work with an arbitrary Bounded type).

#minimum Source

minimum :: forall a. Bounded a => Fold a a

A Fold which computes the minimum of its inputs (generalized to work with an arbitrary Bounded type).

#elem Source

elem :: forall a. Eq a => a -> Fold a Boolean

A Fold which tests if a specific value appeared as an input.

#notElem Source

notElem :: forall a. Eq a => a -> Fold a Boolean

A Fold which tests if a specific value did not appear as an input.

#distributed Source

distributed :: forall b a f. Distributive f => Fold a b -> Fold (f a) (f b)

Fold over entire collections of inputs, producing a collection of outputs.

Modules
Control.Fold