LocalDependency.Data.Foldable
#Foldable
class Foldable :: (Type -> Type) -> Constraintclass Foldable f where
Foldable represents data structures which can be folded.
foldrfolds a structure from the rightfoldlfolds a structure from the leftfoldMapfolds a structure by accumulating values in aMonoid
Default implementations are provided by the following functions:
foldrDefaultfoldlDefaultfoldMapDefaultRfoldMapDefaultL
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.
Members
foldr :: forall a b. (a -> b -> b) -> b -> f a -> bfoldl :: forall a b. (b -> a -> b) -> b -> f a -> bfoldMap :: forall a m. Monoid m => (a -> m) -> f a -> m
Instances
Foldable ArrayFoldable MaybeFoldable FirstFoldable LastFoldable AdditiveFoldable DualFoldable DisjFoldable ConjFoldable MultiplicativeFoldable (Either a)Foldable (Tuple a)Foldable IdentityFoldable (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)
#foldrDefault
foldrDefault :: forall f a b. Foldable f => (a -> b -> b) -> b -> f a -> bA default implementation of foldr using foldMap.
Note: when defining a Foldable instance, this function is unsafe to use
in combination with foldMapDefaultR.
#foldlDefault
foldlDefault :: forall f a b. Foldable f => (b -> a -> b) -> b -> f a -> bA default implementation of foldl using foldMap.
Note: when defining a Foldable instance, this function is unsafe to use
in combination with foldMapDefaultL.
#foldMapDefaultL
foldMapDefaultL :: forall f a m. Foldable f => Monoid m => (a -> m) -> f a -> mA default implementation of foldMap using foldl.
Note: when defining a Foldable instance, this function is unsafe to use
in combination with foldlDefault.
#foldMapDefaultR
foldMapDefaultR :: forall f a m. Foldable f => Monoid m => (a -> m) -> f a -> mA default implementation of foldMap using foldr.
Note: when defining a Foldable instance, this function is unsafe to use
in combination with foldrDefault.
#fold
#foldM
#traverse_
traverse_ :: forall a b f m. Applicative m => Foldable f => (a -> m b) -> f a -> m UnitTraverse a data structure, performing some effects encoded by an
Applicative functor at each value, ignoring the final result.
For example:
traverse_ print [1, 2, 3]
#for_
for_ :: forall a b f m. Applicative m => Foldable f => f a -> (a -> m b) -> m UnitA 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 example:
for_ [1, 2, 3] \n -> do
print n
trace "squared is"
print (n * n)
#sequence_
sequence_ :: forall a f m. Applicative m => Foldable f => f (m a) -> m UnitPerform all of the effects in some data structure in the order
given by the Foldable instance, ignoring the final result.
For example:
sequence_ [ trace "Hello, ", trace " world!" ]
#oneOf
#oneOfMap
#intercalate
intercalate :: forall f m. Foldable f => Monoid m => m -> f m -> mFold a data structure, accumulating values in some Monoid,
combining adjacent elements using the specified separator.
For example:
> intercalate ", " ["Lorem", "ipsum", "dolor"]
= "Lorem, ipsum, dolor"
> intercalate "*" ["a", "b", "c"]
= "a*b*c"
> intercalate [1] [[2, 3], [4, 5], [6, 7]]
= [2, 3, 1, 4, 5, 1, 6, 7]
#surroundMap
surroundMap :: forall f a m. Foldable f => Semigroup m => m -> (a -> m) -> f a -> mfoldMap but with each element surrounded by some fixed value.
For example:
> surroundMap "*" show []
= "*"
> surroundMap "*" show [1]
= "*1*"
> surroundMap "*" show [1, 2]
= "*1*2*"
> surroundMap "*" show [1, 2, 3]
= "*1*2*3*"
#surround
#and
and :: forall a f. Foldable f => HeytingAlgebra a => f a -> aThe conjunction of all the values in a data structure. When specialized
to Boolean, this function will test whether all of the values in a data
structure are true.
#or
or :: forall a f. Foldable f => HeytingAlgebra a => f a -> aThe disjunction of all the values in a data structure. When specialized
to Boolean, this function will test whether any of the values in a data
structure is true.
#all
all :: forall a b f. Foldable f => HeytingAlgebra b => (a -> b) -> f a -> ball f is the same as and <<< map f; map a function over the structure,
and then get the conjunction of the results.
#any
any :: forall a b f. Foldable f => HeytingAlgebra b => (a -> b) -> f a -> bany f is the same as or <<< map f; map a function over the structure,
and then get the disjunction of the results.
#sum
#product
#elem
#notElem
#indexl
#indexr
#find
#findMap
#maximum
#maximumBy
#minimum
#minimumBy
#null
#length
Modules
- Control.Applicative
- Control.Apply
- Control.Bind
- Control.Category
- Control.Monad
- Control.Semigroupoid
- Data.Boolean
- Data.BooleanAlgebra
- Data.Bounded
- Data.Bounded.Generic
- Data.CommutativeRing
- Data.DivisionRing
- Data.Eq
- Data.Eq.Generic
- Data.EuclideanRing
- Data.Field
- Data.Function
- Data.Functor
- Data.Generic.Rep
- Data.HeytingAlgebra
- Data.HeytingAlgebra.Generic
- Data.Monoid
- Data.Monoid.Additive
- Data.Monoid.Conj
- Data.Monoid.Disj
- Data.Monoid.Dual
- Data.Monoid.Endo
- Data.Monoid.Generic
- Data.Monoid.Multiplicative
- Data.NaturalTransformation
- Data.Newtype
- Data.Ord
- Data.Ord.Down
- Data.Ord.Generic
- Data.Ord.Max
- Data.Ord.Min
- Data.Ordering
- Data.Ring
- Data.Ring.Generic
- Data.Semigroup
- Data.Semigroup.First
- Data.Semigroup.Generic
- Data.Semigroup.Last
- Data.Semiring
- Data.Semiring.Generic
- Data.Show
- Data.Show.Generic
- Data.Symbol
- Data.Unit
- Data.Void
- Foreign
- LocalDependency.Control.Alt
- LocalDependency.Control.Alternative
- LocalDependency.Control.Biapplicative
- LocalDependency.Control.Biapply
- LocalDependency.Control.Comonad
- LocalDependency.Control.Extend
- LocalDependency.Control.Lazy
- LocalDependency.Control.MonadPlus
- LocalDependency.Control.MonadZero
- LocalDependency.Control.Plus
- LocalDependency.Data.Bifoldable
- LocalDependency.Data.Bifunctor
- LocalDependency.Data.Bifunctor.Join
- LocalDependency.Data.Bitraversable
- LocalDependency.Data.Comparison
- LocalDependency.Data.Const
- LocalDependency.Data.Decidable
- LocalDependency.Data.Decide
- LocalDependency.Data.Distributive
- LocalDependency.Data.Divide
- LocalDependency.Data.Divisible
- LocalDependency.Data.Either
- LocalDependency.Data.Either.Inject
- LocalDependency.Data.Either.Nested
- LocalDependency.Data.Equivalence
- LocalDependency.Data.Exists
- LocalDependency.Data.Foldable
- LocalDependency.Data.FoldableWithIndex
- LocalDependency.Data.Functor.App
- LocalDependency.Data.Functor.Clown
- LocalDependency.Data.Functor.Compose
- LocalDependency.Data.Functor.Contravariant
- LocalDependency.Data.Functor.Coproduct
- LocalDependency.Data.Functor.Coproduct.Inject
- LocalDependency.Data.Functor.Coproduct.Nested
- LocalDependency.Data.Functor.Costar
- LocalDependency.Data.Functor.Flip
- LocalDependency.Data.Functor.Invariant
- LocalDependency.Data.Functor.Joker
- LocalDependency.Data.Functor.Product
- LocalDependency.Data.Functor.Product.Nested
- LocalDependency.Data.Functor.Product2
- LocalDependency.Data.FunctorWithIndex
- LocalDependency.Data.Identity
- LocalDependency.Data.Maybe
- LocalDependency.Data.Maybe.First
- LocalDependency.Data.Maybe.Last
- LocalDependency.Data.Monoid.Alternate
- LocalDependency.Data.Op
- LocalDependency.Data.Predicate
- LocalDependency.Data.Profunctor
- LocalDependency.Data.Profunctor.Choice
- LocalDependency.Data.Profunctor.Closed
- LocalDependency.Data.Profunctor.Cochoice
- LocalDependency.Data.Profunctor.Costrong
- LocalDependency.Data.Profunctor.Join
- LocalDependency.Data.Profunctor.Split
- LocalDependency.Data.Profunctor.Star
- LocalDependency.Data.Profunctor.Strong
- LocalDependency.Data.Semigroup.Foldable
- LocalDependency.Data.Semigroup.Traversable
- LocalDependency.Data.Traversable
- LocalDependency.Data.Traversable.Accum
- LocalDependency.Data.Traversable.Accum.Internal
- LocalDependency.Data.TraversableWithIndex
- LocalDependency.Data.Tuple
- LocalDependency.Data.Tuple.Nested
- LocalDependency.Effect
- LocalDependency.Safe.Coerce
- LocalDependency.Type.Equality
- LocalDependency.Unsafe.Coerce
- Prelude
- Prim
- Prim.Boolean
- Prim.Coerce
- Prim.Ordering
- Prim.Row
- Prim.RowList
- Prim.Symbol
- Prim.TypeError
- Record.Unsafe
- Safe.Coerce
- Test.Foreign
- Test.Main
- Test.MiraculixLite
- Test.MiraculixLite.Assertion
- Test.MiraculixLite.FFI
- Test.MiraculixLite.Summary
- Test.MiraculixLite.TestTree
- Test.MiraculixLite.Typo
- Type.Data.Row
- Type.Data.RowList
- Type.Proxy
- Unsafe.Coerce