Copyright | (C) 2011-2016 Edward Kmett |
---|---|

License | BSD-style (see the file LICENSE) |

Maintainer | libraries@haskell.org |

Stability | provisional |

Portability | portable |

Safe Haskell | Safe |

Language | Haskell2010 |

Since: 4.10.0.0

class Bifoldable p where Source

`Bifoldable`

identifies foldable structures with two different varieties of elements (as opposed to `Foldable`

, which has one variety of element). Common examples are `Either`

and '(,)':

instance Bifoldable Either where bifoldMap f _ (Left a) = f a bifoldMap _ g (Right b) = g b instance Bifoldable (,) where bifoldr f g z (a, b) = f a (g b z)

A minimal `Bifoldable`

definition consists of either `bifoldMap`

or `bifoldr`

. When defining more than this minimal set, one should ensure that the following identities hold:

`bifold`

≡`bifoldMap`

`id`

`id`

`bifoldMap`

f g ≡`bifoldr`

(`mappend`

. f) (`mappend`

. g)`mempty`

`bifoldr`

f g z t ≡`appEndo`

(`bifoldMap`

(Endo . f) (Endo . g) t) z

If the type is also a `Bifunctor`

instance, it should satisfy:

'bifoldMap' f g ≡ 'bifold' . 'bimap' f g

which implies that

'bifoldMap' f g . 'bimap' h i ≡ 'bifoldMap' (f . h) (g . i)

Since: 4.10.0.0

bifold :: Monoid m => p m m -> m Source

Combines the elements of a structure using a monoid.

`bifold`

≡`bifoldMap`

`id`

`id`

Since: 4.10.0.0

bifoldMap :: Monoid m => (a -> m) -> (b -> m) -> p a b -> m Source

Combines the elements of a structure, given ways of mapping them to a common monoid.

`bifoldMap`

f g ≡`bifoldr`

(`mappend`

. f) (`mappend`

. g)`mempty`

Since: 4.10.0.0

bifoldr :: (a -> c -> c) -> (b -> c -> c) -> c -> p a b -> c Source

Combines the elements of a structure in a right associative manner. Given a hypothetical function `toEitherList :: p a b -> [Either a b]`

yielding a list of all elements of a structure in order, the following would hold:

`bifoldr`

f g z ≡`foldr`

(`either`

f g) z . toEitherList

Since: 4.10.0.0

bifoldl :: (c -> a -> c) -> (c -> b -> c) -> c -> p a b -> c Source

Combines the elments of a structure in a left associative manner. Given a hypothetical function `toEitherList :: p a b -> [Either a b]`

yielding a list of all elements of a structure in order, the following would hold:

`bifoldl`

f g z ≡`foldl`

(acc ->`either`

(f acc) (g acc)) z . toEitherList

Note that if you want an efficient left-fold, you probably want to use `bifoldl'`

instead of `bifoldl`

. The reason is that the latter does not force the "inner" results, resulting in a thunk chain which then must be evaluated from the outside-in.

Since: 4.10.0.0

Bifoldable Either | Since: 4.10.0.0 |

Bifoldable (,) | Since: 4.10.0.0 |

Bifoldable Arg | Since: 4.10.0.0 |

Bifoldable ((,,) x) | Since: 4.10.0.0 |

Bifoldable (Const *) | Since: 4.10.0.0 |

Bifoldable (K1 * i) | Since: 4.10.0.0 |

Bifoldable ((,,,) x y) | Since: 4.10.0.0 |

Bifoldable ((,,,,) x y z) | Since: 4.10.0.0 |

Bifoldable ((,,,,,) x y z w) | Since: 4.10.0.0 |

Bifoldable ((,,,,,,) x y z w v) | Since: 4.10.0.0 |

bifoldr' :: Bifoldable t => (a -> c -> c) -> (b -> c -> c) -> c -> t a b -> c Source

As `bifoldr`

, but strict in the result of the reduction functions at each step.

Since: 4.10.0.0

bifoldr1 :: Bifoldable t => (a -> a -> a) -> t a a -> a Source

A variant of `bifoldr`

that has no base case, and thus may only be applied to non-empty structures.

Since: 4.10.0.0

bifoldrM :: (Bifoldable t, Monad m) => (a -> c -> m c) -> (b -> c -> m c) -> c -> t a b -> m c Source

Right associative monadic bifold over a structure.

Since: 4.10.0.0

bifoldl' :: Bifoldable t => (a -> b -> a) -> (a -> c -> a) -> a -> t b c -> a Source

As `bifoldl`

, but strict in the result of the reduction functions at each step.

This ensures that each step of the bifold is forced to weak head normal form before being applied, avoiding the collection of thunks that would otherwise occur. This is often what you want to strictly reduce a finite structure to a single, monolithic result (e.g., `bilength`

).

Since: 4.10.0.0

bifoldl1 :: Bifoldable t => (a -> a -> a) -> t a a -> a Source

A variant of `bifoldl`

that has no base case, and thus may only be applied to non-empty structures.

Since: 4.10.0.0

bifoldlM :: (Bifoldable t, Monad m) => (a -> b -> m a) -> (a -> c -> m a) -> a -> t b c -> m a Source

Left associative monadic bifold over a structure.

Since: 4.10.0.0

bitraverse_ :: (Bifoldable t, Applicative f) => (a -> f c) -> (b -> f d) -> t a b -> f () Source

Map each element of a structure using one of two actions, evaluate these actions from left to right, and ignore the results. For a version that doesn't ignore the results, see `bitraverse`

.

Since: 4.10.0.0

bifor_ :: (Bifoldable t, Applicative f) => t a b -> (a -> f c) -> (b -> f d) -> f () Source

As `bitraverse_`

, but with the structure as the primary argument. For a version that doesn't ignore the results, see `bifor`

.

`>>>`

'a' "cb"`> bifor_ ('a', "bc") print (print . reverse)`

Since: 4.10.0.0

bimapM_ :: (Bifoldable t, Applicative f) => (a -> f c) -> (b -> f d) -> t a b -> f () Source

Alias for `bitraverse_`

.

Since: 4.10.0.0

biforM_ :: (Bifoldable t, Applicative f) => t a b -> (a -> f c) -> (b -> f d) -> f () Source

Alias for `bifor_`

.

Since: 4.10.0.0

bimsum :: (Bifoldable t, Alternative f) => t (f a) (f a) -> f a Source

Alias for `biasum`

.

Since: 4.10.0.0

bisequenceA_ :: (Bifoldable t, Applicative f) => t (f a) (f b) -> f () Source

Alias for `bisequence_`

.

Since: 4.10.0.0

bisequence_ :: (Bifoldable t, Applicative f) => t (f a) (f b) -> f () Source

Evaluate each action in the structure from left to right, and ignore the results. For a version that doesn't ignore the results, see `bisequence`

.

Since: 4.10.0.0

biasum :: (Bifoldable t, Alternative f) => t (f a) (f a) -> f a Source

The sum of a collection of actions, generalizing `biconcat`

.

Since: 4.10.0.0

biList :: Bifoldable t => t a a -> [a] Source

Collects the list of elements of a structure, from left to right.

Since: 4.10.0.0

binull :: Bifoldable t => t a b -> Bool Source

Test whether the structure is empty.

Since: 4.10.0.0

bilength :: Bifoldable t => t a b -> Int Source

Returns the size/length of a finite structure as an `Int`

.

Since: 4.10.0.0

bielem :: (Bifoldable t, Eq a) => a -> t a a -> Bool Source

Does the element occur in the structure?

Since: 4.10.0.0

bimaximum :: forall t a. (Bifoldable t, Ord a) => t a a -> a Source

The largest element of a non-empty structure.

Since: 4.10.0.0

biminimum :: forall t a. (Bifoldable t, Ord a) => t a a -> a Source

The least element of a non-empty structure.

Since: 4.10.0.0

bisum :: (Bifoldable t, Num a) => t a a -> a Source

The `bisum`

function computes the sum of the numbers of a structure.

Since: 4.10.0.0

biproduct :: (Bifoldable t, Num a) => t a a -> a Source

The `biproduct`

function computes the product of the numbers of a structure.

Since: 4.10.0.0

biconcat :: Bifoldable t => t [a] [a] -> [a] Source

Reduces a structure of lists to the concatenation of those lists.

Since: 4.10.0.0

biconcatMap :: Bifoldable t => (a -> [c]) -> (b -> [c]) -> t a b -> [c] Source

Given a means of mapping the elements of a structure to lists, computes the concatenation of all such lists in order.

Since: 4.10.0.0

biand :: Bifoldable t => t Bool Bool -> Bool Source

`biand`

returns the conjunction of a container of Bools. For the result to be `True`

, the container must be finite; `False`

, however, results from a `False`

value finitely far from the left end.

Since: 4.10.0.0

bior :: Bifoldable t => t Bool Bool -> Bool Source

`bior`

returns the disjunction of a container of Bools. For the result to be `False`

, the container must be finite; `True`

, however, results from a `True`

value finitely far from the left end.

Since: 4.10.0.0

biany :: Bifoldable t => (a -> Bool) -> (b -> Bool) -> t a b -> Bool Source

Determines whether any element of the structure satisfies its appropriate predicate argument.

Since: 4.10.0.0

biall :: Bifoldable t => (a -> Bool) -> (b -> Bool) -> t a b -> Bool Source

Determines whether all elements of the structure satisfy their appropriate predicate argument.

Since: 4.10.0.0

bimaximumBy :: Bifoldable t => (a -> a -> Ordering) -> t a a -> a Source

The largest element of a non-empty structure with respect to the given comparison function.

Since: 4.10.0.0

biminimumBy :: Bifoldable t => (a -> a -> Ordering) -> t a a -> a Source

The least element of a non-empty structure with respect to the given comparison function.

Since: 4.10.0.0

binotElem :: (Bifoldable t, Eq a) => a -> t a a -> Bool Source

`binotElem`

is the negation of `bielem`

.

Since: 4.10.0.0

bifind :: Bifoldable t => (a -> Bool) -> t a a -> Maybe a Source

The `bifind`

function takes a predicate and a structure and returns the leftmost element of the structure matching the predicate, or `Nothing`

if there is no such element.

Since: 4.10.0.0

© The University of Glasgow and others

Licensed under a BSD-style license (see top of the page).

https://downloads.haskell.org/~ghc/8.2.1/docs/html/libraries/base-4.10.0.0/Data-Bifoldable.html