class Foldable :: (Type -> Type) -> Constraint
class Foldable f where
Foldable represents data structures which can be folded.
foldrfolds a structure from the right
foldlfolds a structure from the left
foldMapfolds a structure by accumulating values in a
Default implementations are provided by the following functions:
Note: some combinations of the default implementations are unsafe to use together - causing a non-terminating mutually recursive cycle. These combinations are documented per function.
foldr :: forall a b. (a -> b -> b) -> b -> f a -> b
foldl :: forall a b. (b -> a -> b) -> b -> f a -> b
foldMap :: forall a m. Monoid m => (a -> m) -> f a -> m
Foldable (Either a)
Foldable (Tuple a)
Foldable (Const a)
(Foldable f, Foldable g) => Foldable (Product f g)
(Foldable f, Foldable g) => Foldable (Coproduct f g)
(Foldable f, Foldable g) => Foldable (Compose f g)
(Foldable f) => Foldable (App f)
for_ :: forall a b f m. Applicative m => Foldable f => f a -> (a -> m b) -> m Unit
A version of
traverse_ with its arguments flipped.
This can be useful when running an action written using do notation for every element in a data structure:
for_ [1, 2, 3] \n -> do print n trace "squared is" print (n * n)
intercalate :: forall f m. Foldable f => Monoid m => m -> f m -> m
Fold a data structure, accumulating values in some
combining adjacent elements using the specified separator.
> intercalate ", " ["Lorem", "ipsum", "dolor"] = "Lorem, ipsum, dolor" > intercalate "*" ["a", "b", "c"] = "a*b*c" > intercalate  [[2, 3], [4, 5], [6, 7]] = [2, 3, 1, 4, 5, 1, 6, 7]
surroundMap :: forall f a m. Foldable f => Semigroup m => m -> (a -> m) -> f a -> m
foldMap but with each element surrounded by some fixed value.
> surroundMap "*" show  = "*" > surroundMap "*" show  = "*1*" > surroundMap "*" show [1, 2] = "*1*2*" > surroundMap "*" show [1, 2, 3] = "*1*2*3*"