gambler-0.4.1.0: Composable, streaming, and efficient left folds
Safe HaskellSafe-Inferred
LanguageGHC2021

Fold.Pure

Synopsis

Type

data Fold a b Source #

Processes inputs of type a and results in a value of type b

Constructors

forall x. Fold 

Fields

Instances

Instances details
Applicative (Fold a) Source # 
Instance details

Defined in Fold.Pure.Type

Methods

pure :: a0 -> Fold a a0 #

(<*>) :: Fold a (a0 -> b) -> Fold a a0 -> Fold a b #

liftA2 :: (a0 -> b -> c) -> Fold a a0 -> Fold a b -> Fold a c #

(*>) :: Fold a a0 -> Fold a b -> Fold a b #

(<*) :: Fold a a0 -> Fold a b -> Fold a a0 #

Functor (Fold a) Source # 
Instance details

Defined in Fold.Pure.Type

Methods

fmap :: (a0 -> b) -> Fold a a0 -> Fold a b #

(<$) :: a0 -> Fold a b -> Fold a a0 #

Monoid b => Monoid (Fold a b) Source # 
Instance details

Defined in Fold.Pure.Type

Methods

mempty :: Fold a b #

mappend :: Fold a b -> Fold a b -> Fold a b #

mconcat :: [Fold a b] -> Fold a b #

Semigroup b => Semigroup (Fold a b) Source # 
Instance details

Defined in Fold.Pure.Type

Methods

(<>) :: Fold a b -> Fold a b -> Fold a b #

sconcat :: NonEmpty (Fold a b) -> Fold a b #

stimes :: Integral b0 => b0 -> Fold a b -> Fold a 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

semigroup :: Semigroup a => Fold a (Maybe a) Source #

Append each new input on the right with (<>)

monoid :: Monoid a => Fold a a Source #

Start with mempty, append each input on the right with (<>)

Endpoints

first :: Fold a (Maybe a) Source #

The first input

last :: Fold a (Maybe a) Source #

The last input

Extrema

maximum :: Ord a => Fold a (Maybe a) Source #

The greatest input

minimum :: Ord a => Fold a (Maybe a) Source #

The least input

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

null :: Fold a Bool Source #

True if the input contains no inputs

length :: Fold a Natural Source #

The number of inputs

Boolean

and :: Fold Bool Bool Source #

True if all inputs are True

or :: Fold Bool Bool Source #

True if any input is True

all :: (a -> Bool) -> Fold a Bool Source #

True if all inputs satisfy the predicate

any :: (a -> Bool) -> Fold a Bool Source #

True if any input satisfies the predicate

Numeric

sum :: Num a => Fold a a Source #

Adds the inputs

product :: Num a => Fold a a Source #

Multiplies the inputs

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

element :: Eq a => a -> Fold a Bool Source #

True if any input is equal to the given value

notElement :: Eq a => a -> Fold a Bool Source #

False if any input is equal to the given value

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

list :: Fold a [a] Source #

All the inputs

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

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

repeatedly Source #

Arguments

:: forall x xs result. (forall b. Fold x b -> xs -> b)

A witness to the fact that xs is a list of x

-> Fold x result 
-> Fold xs result 

Convert a fold for a single item (x) into a fold for lists of items (xs)

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

predropWhile :: (a -> Bool) -> Fold a r -> Fold a r Source #

Ignores inputs until they stop satisfying a predicate

drop :: Natural -> Fold a b -> Fold a b Source #

Ignores the first n inputs

nest :: Applicative f => Fold a b -> Fold (f a) (f b) Source #

Nest a fold in an applicative