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

Fold.ShortcutNonempty

Synopsis

Type

data ShortcutNonemptyFold a b Source #

Processes at least one input of type a, has the ability to halt midway through the stream, and results in a value of type b

Constructors

forall x y. ShortcutNonemptyFold 

Fields

Instances

Instances details
Applicative (ShortcutNonemptyFold a) Source # 
Instance details

Defined in Fold.ShortcutNonempty.Type

Functor (ShortcutNonemptyFold a) Source # 
Instance details

Defined in Fold.ShortcutNonempty.Type

Methods

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

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

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

Defined in Fold.ShortcutNonempty.Type

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

Defined in Fold.ShortcutNonempty.Type

data Will Source #

Constructors

Ambivalent 
Tenacious 

Instances

Instances details
Monoid Will Source # 
Instance details

Defined in Strict

Methods

mempty :: Will #

mappend :: Will -> Will -> Will #

mconcat :: [Will] -> Will #

Semigroup Will Source # 
Instance details

Defined in Strict

Methods

(<>) :: Will -> Will -> Will #

sconcat :: NonEmpty Will -> Will #

stimes :: Integral b => b -> Will -> Will #

data Vitality a b Source #

Constructors

Dead a 
Alive Will b 

Instances

Instances details
Functor (Vitality a) Source # 
Instance details

Defined in Strict

Methods

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

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

type Vitality' a = Vitality a a Source #

Run

run :: ShortcutNonemptyFold a b -> NonEmpty a -> b Source #

Fold a nonempty listlike container to a single summary result, forcing only enough input to satisfy the short-cutting fold's tenacity

Examples

General

magma :: (a -> a -> a) -> ShortcutNonemptyFold a a Source #

Start with the first input, append each new input on the right with the given function (ambivalent)

semigroup :: Semigroup a => ShortcutNonemptyFold a a Source #

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

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

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

Endpoints

first :: ShortcutNonemptyFold a a Source #

The first input (tenacious)

last :: ShortcutNonemptyFold a a Source #

The last input (ambivalent)

Extrema

maximum :: Ord a => ShortcutNonemptyFold a a Source #

The greatest input (ambivalent)

minimum :: Ord a => ShortcutNonemptyFold a a Source #

The least input (ambivalent)

maximumBy :: (a -> a -> Ordering) -> ShortcutNonemptyFold a a Source #

The greatest input with respect to the given comparison function (ambivalent)

minimumBy :: (a -> a -> Ordering) -> ShortcutNonemptyFold a a Source #

The least input with respect to the given comparison function (ambivalent)

Length

length :: ShortcutNonemptyFold a Natural Source #

The number of inputs (ambivalent)

Boolean

and :: ShortcutNonemptyFold Bool Bool Source #

True if all inputs are True (tenacious)

or :: ShortcutNonemptyFold Bool Bool Source #

True if any input is True (tenacious)

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

True if all inputs satisfy the predicate (tenacious)

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

True if any input satisfies the predicate (tenacious)

Numeric

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

Adds the inputs (ambivalent)

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

Multiplies the inputs (ambivalent)

mean :: Fractional a => ShortcutNonemptyFold a a Source #

Numerically stable arithmetic mean of the inputs (ambivalent)

variance :: Fractional a => ShortcutNonemptyFold a a Source #

Numerically stable (population) variance over the inputs (ambivalent)

standardDeviation :: Floating a => ShortcutNonemptyFold a a Source #

Numerically stable (population) standard deviation over the inputs (ambivalent)

Search

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

True if any input is equal to the given value (tenacious)

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

False if any input is equal to the given value (tenacious)

find :: (a -> Bool) -> ShortcutNonemptyFold a (Maybe a) Source #

The first input that satisfies the predicate, if any (tenacious)

lookup :: Eq a => a -> ShortcutNonemptyFold (a, b) (Maybe b) Source #

The b from the first tuple where a equals the given value, if any (tenacious)

Index

index :: Natural -> ShortcutNonemptyFold a (Maybe a) Source #

The nth input, where n=0 is the first input, if the index is in bounds (tenacious)

findIndex :: (a -> Bool) -> ShortcutNonemptyFold a (Maybe Natural) Source #

The index of the first input that satisfies the predicate, if any (tenacious)

elementIndex :: Eq a => a -> ShortcutNonemptyFold a (Maybe Natural) Source #

The index of the first input that matches the given value, if any (tenacious)

List

list :: ShortcutNonemptyFold a (NonEmpty a) Source #

All the inputs (ambivalent)

reverseList :: ShortcutNonemptyFold a (NonEmpty a) Source #

All the inputs in reverse order (ambivalent)

Conversion

Utilities

demotivate :: ShortcutNonemptyFold a b -> ShortcutNonemptyFold a b Source #

Causes a shortcut fold to stop once it becomes ambivalent

duplicate :: ShortcutNonemptyFold a b -> ShortcutNonemptyFold a (ShortcutFold 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. ShortcutNonemptyFold x b -> xs -> b)

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

-> ShortcutNonemptyFold x result 
-> ShortcutNonemptyFold xs result 

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

premap :: (a -> b) -> ShortcutNonemptyFold b r -> ShortcutNonemptyFold a r Source #

Applies a function to each input before processing