| Safe Haskell | Safe |
|---|
Eta.Classes.Foldable
- class Foldable t where
- foldRight :: Foldable f => (a -> b -> b) -> b -> f a -> b
- foldLeft :: Foldable f => (b -> a -> b) -> b -> f a -> b
- strictFoldRight :: Foldable f => (a -> b -> b) -> b -> f a -> b
- strictFoldLeft :: Foldable f => (b -> a -> b) -> b -> f a -> b
- monadicFoldRight :: (Foldable f, Monad m) => (a -> b -> m b) -> b -> f a -> m b
- monadicFoldLeft :: (Foldable f, Monad m) => (b -> a -> m b) -> b -> f a -> m b
- toList :: Foldable f => f a -> [a]
- isEmpty :: Foldable f => f a -> Bool
- length :: Foldable f => f a -> Int
- isElementOf :: (Eq a, Foldable f) => a -> f a -> Bool
- maximum :: (Ord a, Foldable f) => f a -> Maybe a
- maximumBy :: Foldable f => (a -> a -> Ordering) -> f a -> Maybe a
- unsafeMaximum :: (Ord a, Foldable f) => f a -> a
- minimum :: (Ord a, Foldable f) => f a -> Maybe a
- minimumBy :: Foldable f => (a -> a -> Ordering) -> f a -> Maybe a
- unsafeMinimum :: (Ord a, Foldable f) => f a -> a
- sum :: (Num a, Foldable f) => f a -> a
- product :: (Num a, Foldable f) => f a -> a
- findBy :: Foldable f => (a -> Bool) -> f a -> Maybe a
- any :: Foldable f => (a -> Bool) -> f a -> Bool
- all :: Foldable f => (a -> Bool) -> f a -> Bool
- discardTraverse :: (Foldable f, Applicative m) => (a -> m b) -> f a -> m ()
- foreach :: (Foldable f, Applicative m) => f a -> (a -> m b) -> m ()
Documentation
Instances
| Foldable [] | |
| Foldable Maybe | |
| Foldable V1 | |
| Foldable U1 | |
| Foldable Par1 | |
| Foldable Sum | |
| Foldable Product | |
| Foldable Last | |
| Foldable First | |
| Foldable Dual | |
| Foldable ZipList | |
| Foldable (Either a) | |
| Foldable f => Foldable (Rec1 f) | |
| Foldable (URec Char) | |
| Foldable (URec Double) | |
| Foldable (URec Float) | |
| Foldable (URec Int) | |
| Foldable (URec Word) | |
| Foldable (URec (Ptr ())) | |
| Foldable ((,) a) | |
| Foldable (Array i) | |
| Foldable (Proxy *) | |
| Foldable (K1 i c) | |
| (Foldable f, Foldable g) => Foldable ((:+:) f g) | |
| (Foldable f, Foldable g) => Foldable ((:*:) f g) | |
| (Foldable f, Foldable g) => Foldable ((:.:) f g) | |
| Foldable f => Foldable (M1 i c f) | |
foldLeft :: Foldable f => (b -> a -> b) -> b -> f a -> b #
foldLeft starts from the left, using the lazy evaluation
capabilities of Eta. Note that this will get stuck in an
infite loop if you pass an infite list to it.
strictFoldRight :: Foldable f => (a -> b -> b) -> b -> f a -> b #
A version of foldRight that evaluates the operations inline,
hence strict, the opposite of lazy.
strictFoldLeft :: Foldable f => (b -> a -> b) -> b -> f a -> b #
A version of foldLeft that evaluates the operations inline,
hence strict, the opposite of lazy.
monadicFoldRight :: (Foldable f, Monad m) => (a -> b -> m b) -> b -> f a -> m b #
A version of foldRight that applies functions that are flatmappable,
in the context of a type that implements a monad, and returns the
result produced by the reduction of the structure, wrapped in that type:
>>>:{addIntoMaybe :: Int -> Int -> Maybe Int addIntoMaybe a b = Just (a + b) :}
>>>monadicFoldRight addIntoMaybe 0 [1,2,3]Just 6
monadicFoldLeft :: (Foldable f, Monad m) => (b -> a -> m b) -> b -> f a -> m b #
Left-biased version of monadicFoldRight
isElementOf :: (Eq a, Foldable f) => a -> f a -> Bool #
Checks if the element is contained in the structure.
maximum :: (Ord a, Foldable f) => f a -> Maybe a #
Largest element in a structure.
Returns Nothing if the structure is empty.
maximumBy :: Foldable f => (a -> a -> Ordering) -> f a -> Maybe a #
Given some comparison function, return the maximum of a
structure. Returns Nothing if the structure is empty.
unsafeMaximum :: (Ord a, Foldable f) => f a -> a #
Warning: Partial functions should be avoided
Largest element in a structure. Errors if the structure is empty
minimum :: (Ord a, Foldable f) => f a -> Maybe a #
Smallest element in a structure
Returns Nothing if the structure is empty.
minimumBy :: Foldable f => (a -> a -> Ordering) -> f a -> Maybe a #
Given some comparison function, return the minimum of a
structure. Returns Nothing if the structure is empty.
unsafeMinimum :: (Ord a, Foldable f) => f a -> a #
Warning: Partial functions should be avoided
Largest element in a structure. Errors if the structure is empty
any :: Foldable f => (a -> Bool) -> f a -> Bool #
Determines if any element satisfies the predicate
>>>any (== 1) [1, 2, 3]True>>>any (== 5) [1, 2, 3]False
all :: Foldable f => (a -> Bool) -> f a -> Bool #
Determines if all elements satisfy the predicate
>>>all (== 1) [1, 2, 3]False>>>all (< 5) [1, 2, 3]True
discardTraverse :: (Foldable f, Applicative m) => (a -> m b) -> f a -> m () #
Sometimes we need to apply an action to each one of
the elements. The function discardTraverse maps an
action over each of the elements of the structure
>>>discardTraverse printLine ["Hello", "world", "!"]Hello world !
foreach :: (Foldable f, Applicative m) => f a -> (a -> m b) -> m () #
Another alternative to discardTraverse is to use the
foreach function, which is very familiar to a lot
of developers.
>>>foreach [1..3] printShow1 2 3