class (IsString t, LeftReductive t, LeftGCDMonoid t, FactorialMonoid t) => TextualMonoid t whereThe TextualMonoid class is an extension of FactorialMonoid specialized for monoids that can contain characters. Its methods are generally equivalent to their namesake functions from Data.List and Data.Text, and they satisfy the following laws:
unfoldr splitCharacterPrefix . fromString == id
splitCharacterPrefix . primePrefix == fmap (\(c, t)-> (c, mempty)) . splitCharacterPrefix
map f . fromString == fromString . List.map f
concatMap (fromString . f) . fromString == fromString . List.concatMap f
foldl ft fc a . fromString == List.foldl fc a
foldr ft fc a . fromString == List.foldr fc a
foldl' ft fc a . fromString == List.foldl' fc a
scanl f c . fromString == fromString . List.scanl f c
scanr f c . fromString == fromString . List.scanr f c
mapAccumL f a . fromString == fmap fromString . List.mapAccumL f a
mapAccumL f a . fromString == fmap fromString . List.mapAccumL f a
takeWhile pt pc . fromString == fromString . takeWhile pc
dropWhile pt pc . fromString == fromString . dropWhile pc
mconcat . intersperse (singleton c) . split (== c) == id
find p . fromString == List.find p
elem c . fromString == List.elem cA TextualMonoid may contain non-character data insterspersed between its characters. Every class method that returns a modified TextualMonoid instance generally preserves this non-character data. Methods like foldr can access both the non-character and character data and expect two arguments for the two purposes. For each of these methods there is also a simplified version with underscore in name (like foldr_) that ignores the non-character data.
All of the following expressions are identities:
map id
concatMap singleton
foldl (<>) (\a c-> a <> singleton c) mempty
foldr (<>) ((<>) . singleton) mempty
foldl' (<>) (\a c-> a <> singleton c) mempty
scanl1 (const id)
scanr1 const
uncurry (mapAccumL (,))
uncurry (mapAccumR (,))
takeWhile (const True) (const True)
dropWhile (const False) (const False)
toString undefined . fromString
toText undefined . fromTextMethods
fromText :: Text -> tContructs a new data type instance Like fromString, but from a Text input instead of String.
fromText == fromString . Text.unpacksingleton :: Char -> tCreates a prime monoid containing a single character.
singleton c == fromString [c]splitCharacterPrefix :: t -> Maybe (Char, t)Specialized version of splitPrimePrefix. Every prime factor of a textual monoid must consist of a single character or no character at all.
characterPrefix :: t -> Maybe CharExtracts a single character that prefixes the monoid, if the monoid begins with a character. Otherwise returns Nothing.
characterPrefix == fmap fst . splitCharacterPrefixmap :: (Char -> Char) -> t -> tconcatMap :: (Char -> t) -> t -> ttoString :: (t -> String) -> t -> StringReturns the list of characters the monoid contains, once the argument function converts all its non-character factors into characters.
toText :: (t -> Text) -> t -> Textany :: (Char -> Bool) -> t -> Boolall :: (Char -> Bool) -> t -> Boolfoldl :: (a -> t -> a) -> (a -> Char -> a) -> a -> t -> afoldl' :: (a -> t -> a) -> (a -> Char -> a) -> a -> t -> aStrict version of foldl.
foldr :: (t -> a -> a) -> (Char -> a -> a) -> a -> t -> aThe first argument folds over the non-character prime factors, the second over characters. Otherwise equivalent to 'List.foldl'' from Data.List.
scanl :: (Char -> Char -> Char) -> Char -> t -> tscanl1 :: (Char -> Char -> Char) -> t -> tscanr :: (Char -> Char -> Char) -> Char -> t -> tscanr1 :: (Char -> Char -> Char) -> t -> tmapAccumL :: (a -> Char -> (a, Char)) -> a -> t -> (a, t)mapAccumR :: (a -> Char -> (a, Char)) -> a -> t -> (a, t)takeWhile :: (t -> Bool) -> (Char -> Bool) -> t -> tdropWhile :: (t -> Bool) -> (Char -> Bool) -> t -> tbreak :: (t -> Bool) -> (Char -> Bool) -> t -> (t, t)'break pt pc' is equivalent to
span (not . pt) (not . pc).span :: (t -> Bool) -> (Char -> Bool) -> t -> (t, t)'span pt pc t' is equivalent to
(takeWhile pt pc t, dropWhile pt pc t).spanMaybe :: s -> (s -> t -> Maybe s) -> (s -> Char -> Maybe s) -> t -> (t, t, s)spanMaybe' :: s -> (s -> t -> Maybe s) -> (s -> Char -> Maybe s) -> t -> (t, t, s)Strict version of spanMaybe.
split :: (Char -> Bool) -> t -> [t]Splits the monoid into components delimited by character separators satisfying the given predicate. The characters satisfying the predicate are not a part of the result.
split p == Factorial.split (maybe False p . characterPrefix)find :: (Char -> Bool) -> t -> Maybe Charelem :: Char -> t -> Boolfoldl_ :: (a -> Char -> a) -> a -> t -> afoldl_ = foldl constfoldl_' :: (a -> Char -> a) -> a -> t -> afoldr_ :: (Char -> a -> a) -> a -> t -> atakeWhile_ :: Bool -> (Char -> Bool) -> t -> ttakeWhile_ = takeWhile . constdropWhile_ :: Bool -> (Char -> Bool) -> t -> tdropWhile_ = dropWhile . constbreak_ :: Bool -> (Char -> Bool) -> t -> (t, t)break_ = break . constspan_ :: Bool -> (Char -> Bool) -> t -> (t, t)span_ = span . constspanMaybe_ :: s -> (s -> Char -> Maybe s) -> t -> (t, t, s)spanMaybe_ s = spanMaybe s (const . Just)spanMaybe_' :: s -> (s -> Char -> Maybe s) -> t -> (t, t, s)
Instances12TextualMonoid, …
TextualMonoid StringDefined in monoid-subclasses-1.2.5.1 · Data.Monoid.TextualTextualMonoid ByteStringUTF8Defined in monoid-subclasses-1.2.5.1 · Data.Monoid.Instances.ByteString.UTF8TextualMonoid TextDefined in monoid-subclasses-1.2.5.1 · Data.Monoid.TextualTextualMonoid TextDefined in monoid-subclasses-1.2.5.1 · Data.Monoid.TextualTextualMonoid (Seq Char)Defined in monoid-subclasses-1.2.5.1 · Data.Monoid.TextualTextualMonoid (Vector Char)Defined in monoid-subclasses-1.2.5.1 · Data.Monoid.Instances.CharVector · orphan(Eq a, TextualMonoid a, StableFactorial a, PositiveMonoid a) => TextualMonoid (Concat a)Defined in monoid-subclasses-1.2.5.1 · Data.Monoid.Instances.Concat(Eq a, StableFactorial a, TextualMonoid a) => TextualMonoid (Measured a)Defined in monoid-subclasses-1.2.5.1 · Data.Monoid.Instances.Measured(Eq m, StableFactorial m, TextualMonoid m) => TextualMonoid (Shadowed m)Defined in monoid-subclasses-1.2.5.1 · Data.Monoid.Instances.PrefixMemory(StableFactorial m, TextualMonoid m) => TextualMonoid (LinePositioned m)Defined in monoid-subclasses-1.2.5.1 · Data.Monoid.Instances.Positioned(StableFactorial m, TextualMonoid m) => TextualMonoid (OffsetPositioned m)Defined in monoid-subclasses-1.2.5.1 · Data.Monoid.Instances.Positioned(LeftGCDMonoid a, FactorialMonoid a, TextualMonoid b) => TextualMonoid (Stateful a b)Defined in monoid-subclasses-1.2.5.1 · Data.Monoid.Instances.Stateful