Control.Fold
- Package
- purescript-open-folds
- Repository
- purescript-open-community/purescript-open-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
#unfoldFold Source
unfoldFold :: forall s a b. 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 a b. 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.
#scanl Source
scanl :: forall f a b. 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
.
#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 a b. 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 a b. 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
).
#distributed Source
distributed :: forall f a b. Distributive f => Fold a b -> Fold (f a) (f b)
Fold over entire collections of inputs, producing a collection of outputs.
- Modules
- Control.
Fold