Apply a strict left Fold to lazy text
Modulefoldl-1.4.18Haskell2010
Control.Foldl.Text
Folds for text streams
- 3 types
- 1 class
- 18 values
- Packagefoldl-1.4.18
- Exports22
- LanguageHaskell2010
- LicenceBSD-3-Clause
- SourceText.hs
Folding
2 declarationsApply a strict monadic left FoldM to lazy text
Folds
16 declarationsGet the first character of a text stream or return Nothing if the stream is empty
Get the last character of a text stream or return Nothing if the text stream is empty
Return the length of the text stream in characters
Computes the maximum character
Computes the minimum character
(find predicate) returns the first character that satisfies the predicate
or Nothing if no character satisfies the predicate
(index n) returns the nth character of the text stream, or Nothing if
the stream has an insufficient number of characters
(elemIndex c) returns the index of the first character that equals c,
or Nothing if no character matches
(findIndex predicate) returns the index of the first character that
satisfies the predicate, or Nothing if no character satisfies the
predicate
(count c) returns the number of times c appears
Re-exports
4 declarationsControl.Foldl re-exports the Fold type
Data.Text re-exports the Text type
Efficient representation of a left fold that preserves the fold's step function, initial accumulator, and extraction function
This allows the Applicative instance to assemble derived folds that traverse the container only once
A 'Fold a b' processes elements of type a and results in a value of type b.
Instances15Choice, Closed, Costrong, Profunctor, Semigroupoid, Cosieve, …
Choice FoldDefined in foldl-1.4.18 · Control.FoldlClosed FoldDefined in foldl-1.4.18 · Control.FoldlCostrong FoldDefined in foldl-1.4.18 · Control.FoldlProfunctor FoldDefined in foldl-1.4.18 · Control.FoldlSemigroupoid FoldDefined in foldl-1.4.18 · Control.FoldlCosieve Fold []Defined in foldl-1.4.18 · Control.FoldlFunctor (Fold a)Defined in foldl-1.4.18 · Control.FoldlApplicative (Fold a)Defined in foldl-1.4.18 · Control.FoldlComonad (Fold a)Defined in foldl-1.4.18 · Control.FoldlExtend (Fold a)Defined in foldl-1.4.18 · Control.FoldlFloating b => Floating (Fold a b)Defined in foldl-1.4.18 · Control.FoldlFractional b => Fractional (Fold a b)Defined in foldl-1.4.18 · Control.FoldlNum b => Num (Fold a b)Defined in foldl-1.4.18 · Control.FoldlSemigroup b => Semigroup (Fold a b)Defined in foldl-1.4.18 · Control.FoldlMonoid b => Monoid (Fold a b)Defined in foldl-1.4.18 · Control.Foldl
Instances9Profunctor, Functor, Applicative, Extend, Floating, Fractional, …
Functor m => Profunctor (FoldM m)Defined in foldl-1.4.18 · Control.FoldlFunctor m => Functor (FoldM m a)Defined in foldl-1.4.18 · Control.FoldlApplicative m => Applicative (FoldM m a)Defined in foldl-1.4.18 · Control.FoldlMonad m => Extend (FoldM m a)Defined in foldl-1.4.18 · Control.Foldl(Monad m, Floating b) => Floating (FoldM m a b)Defined in foldl-1.4.18 · Control.Foldl(Monad m, Fractional b) => Fractional (FoldM m a b)Defined in foldl-1.4.18 · Control.Foldl(Monad m, Num b) => Num (FoldM m a b)Defined in foldl-1.4.18 · Control.Foldl(Semigroup b, Monad m) => Semigroup (FoldM m a b)Defined in foldl-1.4.18 · Control.Foldl(Monoid b, Monad m) => Monoid (FoldM m a b)Defined in foldl-1.4.18 · Control.Foldl
The Foldable class represents data structures that can be reduced to a summary value one element at a time. Strict left-associative folds are a good fit for space-efficient reduction, while lazy right-associative folds are a good fit for corecursive iteration, or for folds that short-circuit after processing an initial subsequence of the structure's elements.
Instances can be derived automatically by enabling the DeriveFoldable
extension. For example, a derived instance for a binary tree might be:
{-# LANGUAGE DeriveFoldable #-}
data Tree a = Empty
| Leaf a
| Node (Tree a) a (Tree a)
deriving FoldableA more detailed description can be found in the Overview section of
Data.Foldable#overview.
For the class laws see the Laws section of Data.Foldable#laws.
Instances89Foldable, …
Foldable ComplexDefined in base-4.20.2.0 · Data.ComplexFoldable FirstDefined in base-4.20.2.0 · Data.SemigroupFoldable LastDefined in base-4.20.2.0 · Data.SemigroupFoldable MaxDefined in base-4.20.2.0 · Data.SemigroupFoldable MinDefined in base-4.20.2.0 · Data.SemigroupFoldable SCCDefined in containers-0.7 · Data.GraphFoldable IntMapDefined in containers-0.7 · Data.IntMap.InternalFolds in order of increasing key.
Foldable DigitDefined in containers-0.7 · Data.Sequence.InternalFoldable ElemDefined in containers-0.7 · Data.Sequence.InternalFoldable FingerTreeDefined in containers-0.7 · Data.Sequence.InternalFoldable NodeDefined in containers-0.7 · Data.Sequence.InternalFoldable SeqDefined in containers-0.7 · Data.Sequence.InternalFoldable ViewLDefined in containers-0.7 · Data.Sequence.InternalFoldable ViewRDefined in containers-0.7 · Data.Sequence.InternalFoldable SetDefined in containers-0.7 · Data.Set.InternalFolds in order of increasing key.
Foldable TreeDefined in containers-0.7 · Data.TreeFolds in preorder
Foldable MaybeSDefined in containers-0.7 · Utils.Containers.Internal.StrictMaybeFoldable NonEmptyDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.FoldableFoldable IdentityDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.IdentityFoldable FirstDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.FoldableFoldable LastDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.FoldableFoldable DownDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.FoldableFoldable DualDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.FoldableFoldable ProductDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.FoldableFoldable SumDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.FoldableFoldable ZipListDefined in ghc-internal-9.1003.0 · GHC.Internal.Functor.ZipListFoldable Par1Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.FoldableFoldable MaybeDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.FoldableFoldable SoloDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.FoldableFoldable HashedDefined in hashable-1.4.7.0 · Data.Hashable.ClassFoldable ArrayDefined in primitive-0.9.1.0 · Data.Primitive.ArrayFoldable SmallArrayDefined in primitive-0.9.1.0 · Data.Primitive.SmallArrayFoldable TyVarBndrDefined in template-haskell-2.22.0.0 · Language.Haskell.TH.SyntaxFoldable HashSetDefined in unordered-containers-0.2.21 · Data.HashSet.InternalFoldable VectorDefined in vector-0.13.2.0 · Data.VectorFoldable VectorDefined in vector-0.13.2.0 · Data.Vector.StrictFoldable []Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.FoldableFoldable ProxyDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.FoldableFoldable U1Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.FoldableFoldable UAddrDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.FoldableFoldable UCharDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.FoldableFoldable UDoubleDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.FoldableFoldable UFloatDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.FoldableFoldable UIntDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.FoldableFoldable UWordDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.FoldableFoldable V1Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.FoldableFoldable (Arg a)Defined in base-4.20.2.0 · Data.SemigroupFoldable (Map k)Defined in containers-0.7 · Data.Map.InternalFolds in order of increasing key.
Foldable (Array i)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.FoldableFoldable (Either a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.FoldableFoldable (Tuple2 a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.FoldableFoldable (HashMap k)Defined in unordered-containers-0.2.21 · Data.HashMap.InternalFoldable f => Foldable (Lift f)Defined in transformers-0.6.1.1 · Control.Applicative.LiftFoldable f => Foldable (MaybeT f)Defined in transformers-0.6.1.1 · Control.Monad.Trans.MaybeFoldable m => Foldable (CatchT m)Defined in exceptions-0.10.9 · Control.Monad.Catch.PureBifoldable p => Foldable (Fix p)Defined in bifunctors-5.6.2 · Data.Bifunctor.FixBifoldable p => Foldable (Join p)Defined in bifunctors-5.6.2 · Data.Bifunctor.JoinFoldable (Const m)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.ConstFoldable (Baz t b)Defined in profunctors-5.6.3 · Data.Profunctor.TraversingFoldable (Tagged s)Defined in tagged-0.8.9 · Data.TaggedFoldable (Constant a)Defined in transformers-0.6.1.1 · Data.Functor.ConstantFoldable (bi a) => Foldable (Biap bi a)Defined in bifunctors-5.6.2 · Data.Bifunctor.BiapFoldable f => Foldable (Ap f)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.FoldableFoldable f => Foldable (Alt f)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.FoldableFoldable f => Foldable (Rec1 f)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.FoldableFoldable f => Foldable (Backwards f)Defined in transformers-0.6.1.1 · Control.Applicative.BackwardsDerived instance.
Foldable f => Foldable (ExceptT e f)Defined in transformers-0.6.1.1 · Control.Monad.Trans.ExceptFoldable f => Foldable (IdentityT f)Defined in transformers-0.6.1.1 · Control.Monad.Trans.IdentityFoldable f => Foldable (WriterT w f)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Writer.LazyFoldable f => Foldable (WriterT w f)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Writer.StrictFoldable f => Foldable (Reverse f)Defined in transformers-0.6.1.1 · Data.Functor.ReverseFold from right to left.
Foldable w => Foldable (EnvT e w)Defined in comonad-5.0.9 · Control.Comonad.Trans.EnvFoldable (K1 i c)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.FoldableFoldable (Forget r a)Defined in profunctors-5.6.3 · Data.Profunctor.Types(Foldable f, Foldable g) => Foldable (Product f g)Defined in base-4.20.2.0 · Data.Functor.Product(Foldable f, Foldable g) => Foldable (Sum f g)Defined in base-4.20.2.0 · Data.Functor.Sum(Foldable f, Foldable g) => Foldable (f :*: g)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Foldable(Foldable f, Foldable g) => Foldable (f :+: g)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.FoldableBifoldable p => Foldable (Flip p a)Defined in bifunctors-5.6.2 · Data.Bifunctor.FlipBifoldable p => Foldable (WrappedBifunctor p a)Defined in bifunctors-5.6.2 · Data.Bifunctor.WrappedFoldable (Clown f a)Defined in bifunctors-5.6.2 · Data.Bifunctor.ClownFoldable f => Foldable (M1 i c f)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.FoldableFoldable g => Foldable (Joker g a)Defined in bifunctors-5.6.2 · Data.Bifunctor.Joker(Foldable f, Foldable g) => Foldable (Compose f g)Defined in base-4.20.2.0 · Data.Functor.Compose(Foldable f, Foldable g) => Foldable (f :.: g)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Foldable(Foldable (f a), Foldable (g a)) => Foldable (Product f g a)Defined in bifunctors-5.6.2 · Data.Bifunctor.Product(Foldable (f a), Foldable (g a)) => Foldable (Sum f g a)Defined in bifunctors-5.6.2 · Data.Bifunctor.Sum(Foldable f, Bifoldable p) => Foldable (Tannen f p a)Defined in bifunctors-5.6.2 · Data.Bifunctor.Tannen(Bifoldable p, Foldable g) => Foldable (Biff p f g a)Defined in bifunctors-5.6.2 · Data.Bifunctor.Biff
A space efficient, packed, unboxed Unicode text type.
Instances15IsList, Eq, Data, Ord, Read, Show, …
IsList TextDefined in text-2.1.3 · Data.Text · orphanPerforms replacement on invalid scalar values:
Example2 expressions :set -XOverloadedLists['\55555'] :: Text"\65533"
Eq TextDefined in text-2.1.3 · Data.Text · orphanData TextDefined in text-2.1.3 · Data.Text · orphanThis instance preserves data abstraction at the cost of inefficiency. We omit reflection services for the sake of data abstraction.
This instance was created by copying the updated behavior of
Data.Set.Set andData.Map.Data.Map.Map. If you feel a mistake has been made, please feel free to submit improvements.The original discussion is archived here: could we get a Data instance for Data.Text.Text?
The followup discussion that changed the behavior of Set and
Data.Map.Mapis archived here: Proposal: Allow gunfold for Data.Map, ...Ord TextDefined in text-2.1.3 · Data.Text · orphanRead TextDefined in text-2.1.3 · Data.Text · orphanShow TextDefined in text-2.1.3 · Data.Text.Show · orphanIsString TextDefined in text-2.1.3 · Data.Text · orphanPerforms replacement on invalid scalar values:
Example2 expressions :set -XOverloadedStrings"\55555" :: Text"\65533"
Semigroup TextDefined in text-2.1.3 · Data.Text · orphanBeware:
stimeswill crash if the given number does not fit into anInt.Monoid TextDefined in text-2.1.3 · Data.Text · orphanPrintfArg TextDefined in text-2.1.3 · Data.Text · orphanNFData TextDefined in text-2.1.3 · Data.Text · orphanBinary TextDefined in text-2.1.3 · Data.Text · orphanHashable TextDefined in hashable-1.4.7.0 · Data.Hashable.ClassLift TextDefined in text-2.1.3 · Data.Text · orphantype Item Text = CharDefined in text-2.1.3 · Data.Text · orphan