red-g / accumulate / Reduce

Simple, extensible reducers.

Reducers


type alias Reduce a =
Fold a a

Combines two of the same thing. Equivalent to a Fold where the accumulator and input share the same type.

Manipulations

custom : (a -> a -> a) -> Reduce a

Construct a reducer from the given function, where the first and second arguments are the left and right inputs respectively.

combine : Reduce a -> a -> a -> a

Combine two values with a reducer.

flip : Reduce a -> Reduce a

Flip the left and right inputs to a reducer.

collect : Splitter b a -> (Reduce b -> Fold a b) -> Reduce b -> a -> Maybe b

Reduce over a collection. The initial state is split off of the collection. The accumulator is the reducer's left input.

wrap : (a -> a) -> Reduce a -> Reduce a

Apply an operation to the right input of a reducer.

Primitive Reducers

fAdd : Reduce Basics.Float

Add the right float to the left float.

fDiv : Reduce Basics.Float

Divide the left float by the right float.

fMul : Reduce Basics.Int

Multiply the right float by the left float.

fPow : Reduce Basics.Float

Put the left float to the power of the right float.

fSub : Reduce Basics.Float

Subtract the right float from the left float.

iAdd : Reduce Basics.Int

Add the right int to the left int.

iDiv : Reduce Basics.Int

Divide the left integer by the right integer.

iMul : Reduce Basics.Int

Multiply the right integer by the left integer.

iPow : Reduce Basics.Int

Put the left integer to the power of the right integer.

iSub : Reduce Basics.Int

Subtract the right int from the left int.

array : Reduce (Array a)

Append the right array to the left array.

list : Reduce (List a)

Append the right list to the left list.

max : Sorter k -> Reduce k

Keep the larger input, according to the given sorter.

min : Sorter k -> Reduce k

Keep the smaller input, according to the given sorter.

string : Reduce String

Append the right string to the left string.

or : Reduce (Filter a)

Pass the filter if one filter passes.

and : Reduce (Filter a)

Pass the filter if both filters pass.

sorter : Reduce (Sorter a)

Sort by both the left and right filter, deferring to the left.

Composite Reducers

arrayLeft : Reduce a -> Array a -> Maybe a

Reduce an array from the left.

arrayRight : Reduce a -> Array a -> Maybe a

Reduce an array from the right.

stringLeft : Reduce Char -> String -> Maybe Char

Reduce a string from the left.

listLeft : Reduce a -> List a -> Maybe a

Reduce a list from the left.

maybe : Reduce a -> Reduce (Maybe a)

Keep all Just values, reducing if both are present.

result : Reduce e -> Reduce a -> Reduce (Result e a)

Keep all Ok values, reducing if both are present.

resultError : Reduce e -> Reduce a -> Reduce (Result e a)

Keep all Err values, reducing if both are present.