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
#unfoldFold Source
unfoldFold :: forall b a s. s -> (s -> a -> s) -> (s -> b) -> Fold a bCreate 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 bCreate 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 b a f. Traversable f => Fold a b -> f a -> f bRun 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 bA 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 bA 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 bA 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 bA Fold which tests if all of its inputs satisfy some predicate
(generalized to work with an arbitrary HeytingAlgebra).
#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