folds-0.6.2: Beautiful Folding

Safe HaskellTrustworthy

Data.Fold.Class

Synopsis

Documentation

class Choice p => Scan p whereSource

Methods

prefix1 :: a -> p a b -> p a bSource

postfix1 :: p a b -> a -> p a bSource

run1 :: a -> p a b -> bSource

Apply a Folding to a single element of input

interspersing :: a -> p a b -> p a bSource

Instances

class Scan p => Folding p whereSource

Methods

prefix :: Foldable t => t a -> p a b -> p a bSource

Partially apply a Folding to some initial input on the left.

prefixOf :: Fold s a -> s -> p a b -> p a bSource

postfix :: Foldable t => p a b -> t a -> p a bSource

postfixOf :: Fold s a -> p a b -> s -> p a bSource

run :: Foldable t => t a -> p a b -> bSource

Apply a Folding to a container full of input:

>>> run ["hello","world"] $ L id (++) []
"helloworld"
>>> run [1,2,3] $ L id (+) 0
6

runOf :: Fold s a -> s -> p a b -> bSource

filtering :: (a -> Bool) -> p a b -> p a bSource

Instances

Folding L

efficient prefix, leaky postfix

Folding L'

efficient prefix, leaky postfix

Folding M

efficient prefix, efficient postfix

Folding R

leaky prefix, efficient postfix

beneath :: Profunctor p => Optic p Identity s t a b -> p a b -> p s tSource

Lift a Folding into a Prism.

This acts like a generalized notion of "costrength", when applied to a Folding, causing it to return the left-most value that fails to match the Prism, or the result of accumulating rewrapped in the Prism if everything matches.

>>> run [Left 1, Left 2, Left 3] $ beneath _Left $ R id (+) 0
Left 6
>>> run [Left 1, Right 2, Right 3] $ beneath _Left $ R id (+) 0
Right 2
 beneath :: Prism s t a b -> p a b -> p s t
 beneath :: Iso s t a b   -> p a b -> p s t