Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
Synopsis
- data Fold a b = forall x.Fold {}
- run :: Foldable f => Fold a b -> f a -> b
- scan :: Foldable f => Fold a b -> f a -> [b]
- prescan :: Traversable t => Fold a b -> t a -> t b
- postscan :: Traversable t => Fold a b -> t a -> t b
- magma :: (a -> a -> a) -> Fold a (Maybe a)
- semigroup :: Semigroup a => Fold a (Maybe a)
- monoid :: Monoid a => Fold a a
- first :: Fold a (Maybe a)
- last :: Fold a (Maybe a)
- maximum :: Ord a => Fold a (Maybe a)
- minimum :: Ord a => Fold a (Maybe a)
- maximumBy :: (a -> a -> Ordering) -> Fold a (Maybe a)
- minimumBy :: (a -> a -> Ordering) -> Fold a (Maybe a)
- null :: Fold a Bool
- length :: Fold a Natural
- and :: Fold Bool Bool
- or :: Fold Bool Bool
- all :: (a -> Bool) -> Fold a Bool
- any :: (a -> Bool) -> Fold a Bool
- sum :: Num a => Fold a a
- product :: Num a => Fold a a
- mean :: Fractional a => Fold a a
- variance :: Fractional a => Fold a a
- standardDeviation :: Floating a => Fold a a
- element :: Eq a => a -> Fold a Bool
- notElement :: Eq a => a -> Fold a Bool
- find :: (a -> Bool) -> Fold a (Maybe a)
- lookup :: Eq a => a -> Fold (a, b) (Maybe b)
- index :: Natural -> Fold a (Maybe a)
- findIndex :: (a -> Bool) -> Fold a (Maybe Natural)
- elementIndex :: Eq a => a -> Fold a (Maybe Natural)
- list :: Fold a [a]
- reverseList :: Fold a [a]
- effectfulFold :: EffectfulFold Identity a b -> Fold a b
- nonemptyFold :: NonemptyFold a b -> Fold a (Maybe b)
- shortcutFold :: ShortcutFold a b -> Fold a b
- shortcutNonemptyFold :: ShortcutNonemptyFold a b -> Fold a (Maybe b)
- duplicate :: Fold a b -> Fold a (Fold a b)
- premap :: (a -> b) -> Fold b r -> Fold a r
- prefilter :: (a -> Bool) -> Fold a r -> Fold a r
- predropWhile :: (a -> Bool) -> Fold a r -> Fold a r
- drop :: Natural -> Fold a b -> Fold a b
- nest :: Applicative f => Fold a b -> Fold (f a) (f b)
Type
Processes inputs of type a
and results in a value of type b
Run
run :: Foldable f => Fold a b -> f a -> b Source #
Fold a listlike container to a single summary result
run monoid
["a", "b", "c"] = "abc"
scan :: Foldable f => Fold a b -> f a -> [b] Source #
Rather than only obtain a single final result, scanning gives a running total that shows the intermediate result at each step along the way
scan monoid
["a", "b", "c"] = ["","a","ab","abc"]
prescan :: Traversable t => Fold a b -> t a -> t b Source #
Scan where the last input is excluded
prescan monoid
["a", "b", "c"] = ["","a","ab"]
postscan :: Traversable t => Fold a b -> t a -> t b Source #
Scan where the first input is excluded
postscan monoid
["a", "b", "c"] = ["a","ab","abc"]
Examples
General
magma :: (a -> a -> a) -> Fold a (Maybe a) Source #
Start with the first input, append each new input on the right with the given function
Endpoints
Extrema
maximumBy :: (a -> a -> Ordering) -> Fold a (Maybe a) Source #
The greatest input with respect to the given comparison function
minimumBy :: (a -> a -> Ordering) -> Fold a (Maybe a) Source #
The least input with respect to the given comparison function
Length
Boolean
Numeric
mean :: Fractional a => Fold a a Source #
Numerically stable arithmetic mean of the inputs
variance :: Fractional a => Fold a a Source #
Numerically stable (population) variance over the inputs
standardDeviation :: Floating a => Fold a a Source #
Numerically stable (population) standard deviation over the inputs
Search
find :: (a -> Bool) -> Fold a (Maybe a) Source #
The first input that satisfies the predicate, if any
lookup :: Eq a => a -> Fold (a, b) (Maybe b) Source #
The b
from the first tuple where a
equals the given value, if any
Index
index :: Natural -> Fold a (Maybe a) Source #
The nth input, where n=0 is the first input, if the index is in bounds
findIndex :: (a -> Bool) -> Fold a (Maybe Natural) Source #
The index of the first input that satisfies the predicate, if any
elementIndex :: Eq a => a -> Fold a (Maybe Natural) Source #
The index of the first input that matches the given value, if any
List
reverseList :: Fold a [a] Source #
All the inputs in reverse order
Conversion
effectfulFold :: EffectfulFold Identity a b -> Fold a b Source #
Turn an effectful fold into a pure fold
nonemptyFold :: NonemptyFold a b -> Fold a (Maybe b) Source #
Turn a fold that requires at least one input into a fold that returns
Nothing
when there are no inputs
shortcutFold :: ShortcutFold a b -> Fold a b Source #
shortcutNonemptyFold :: ShortcutNonemptyFold a b -> Fold a (Maybe b) Source #
Utilities
duplicate :: Fold a b -> Fold a (Fold a b) Source #
Allows to continue feeding a fold even after passing it to a function that closes it
premap :: (a -> b) -> Fold b r -> Fold a r Source #
Applies a function to each input before processing
prefilter :: (a -> Bool) -> Fold a r -> Fold a r Source #
Consider only inputs that match a predicate