monoid-subclasses-0.4.6: Subclasses of Monoid

Safe HaskellNone
LanguageHaskell2010

Data.Monoid.Instances.ByteString.UTF8

Description

This module defines the ByteStringUTF8 newtype wrapper around ByteString, together with its TextualMonoid instance. The FactorialMonoid instance of a wrapped ByteStringUTF8 value differs from the original ByteString: the prime factors of the original value are its bytes, and for the wrapped value the prime factors are its valid UTF8 byte sequences. The following example session demonstrates the relationship:

> let utf8@(ByteStringUTF8 bs) = fromString "E=mc\xb2"
> bs
"E=mc\194\178"
> factors bs
["E","=","m","c","\194","\178"]
> utf8
"E=mc²"
> factors utf8
["E","=","m","c","²"]

The TextualMonoid instance follows the same logic, but it also decodes all valid UTF8 sequences into characters. Any invalid UTF8 byte sequence from the original ByteString is preserved as a single prime factor:

> let utf8'@(ByteStringUTF8 bs') = ByteStringUTF8 (Data.ByteString.map pred bs)
> bs'
"D<lb\193\177"
> factors bs'
["D","<","l","b","\193","\177"]
> utf8'
"D<lb\[193,177]"
> factors utf8'
["D","<","l","b","\[193,177]"]

Synopsis

Documentation

newtype ByteStringUTF8 Source #

Instances

Eq ByteStringUTF8 Source # 
Ord ByteStringUTF8 Source # 
Show ByteStringUTF8 Source # 
IsString ByteStringUTF8 Source # 
Semigroup ByteStringUTF8 Source # 
Monoid ByteStringUTF8 Source # 
LeftGCDMonoid ByteStringUTF8 Source # 
LeftCancellativeMonoid ByteStringUTF8 Source # 
LeftReductiveMonoid ByteStringUTF8 Source # 
PositiveMonoid ByteStringUTF8 Source # 
MonoidNull ByteStringUTF8 Source # 
FactorialMonoid ByteStringUTF8 Source # 

Methods

factors :: ByteStringUTF8 -> [ByteStringUTF8] Source #

primePrefix :: ByteStringUTF8 -> ByteStringUTF8 Source #

primeSuffix :: ByteStringUTF8 -> ByteStringUTF8 Source #

splitPrimePrefix :: ByteStringUTF8 -> Maybe (ByteStringUTF8, ByteStringUTF8) Source #

splitPrimeSuffix :: ByteStringUTF8 -> Maybe (ByteStringUTF8, ByteStringUTF8) Source #

inits :: ByteStringUTF8 -> [ByteStringUTF8] Source #

tails :: ByteStringUTF8 -> [ByteStringUTF8] Source #

foldl :: (a -> ByteStringUTF8 -> a) -> a -> ByteStringUTF8 -> a Source #

foldl' :: (a -> ByteStringUTF8 -> a) -> a -> ByteStringUTF8 -> a Source #

foldr :: (ByteStringUTF8 -> a -> a) -> a -> ByteStringUTF8 -> a Source #

length :: ByteStringUTF8 -> Int Source #

foldMap :: Monoid n => (ByteStringUTF8 -> n) -> ByteStringUTF8 -> n Source #

span :: (ByteStringUTF8 -> Bool) -> ByteStringUTF8 -> (ByteStringUTF8, ByteStringUTF8) Source #

break :: (ByteStringUTF8 -> Bool) -> ByteStringUTF8 -> (ByteStringUTF8, ByteStringUTF8) Source #

split :: (ByteStringUTF8 -> Bool) -> ByteStringUTF8 -> [ByteStringUTF8] Source #

takeWhile :: (ByteStringUTF8 -> Bool) -> ByteStringUTF8 -> ByteStringUTF8 Source #

dropWhile :: (ByteStringUTF8 -> Bool) -> ByteStringUTF8 -> ByteStringUTF8 Source #

spanMaybe :: s -> (s -> ByteStringUTF8 -> Maybe s) -> ByteStringUTF8 -> (ByteStringUTF8, ByteStringUTF8, s) Source #

spanMaybe' :: s -> (s -> ByteStringUTF8 -> Maybe s) -> ByteStringUTF8 -> (ByteStringUTF8, ByteStringUTF8, s) Source #

splitAt :: Int -> ByteStringUTF8 -> (ByteStringUTF8, ByteStringUTF8) Source #

drop :: Int -> ByteStringUTF8 -> ByteStringUTF8 Source #

take :: Int -> ByteStringUTF8 -> ByteStringUTF8 Source #

reverse :: ByteStringUTF8 -> ByteStringUTF8 Source #

TextualMonoid ByteStringUTF8 Source # 

Methods

fromText :: Text -> ByteStringUTF8 Source #

singleton :: Char -> ByteStringUTF8 Source #

splitCharacterPrefix :: ByteStringUTF8 -> Maybe (Char, ByteStringUTF8) Source #

characterPrefix :: ByteStringUTF8 -> Maybe Char Source #

map :: (Char -> Char) -> ByteStringUTF8 -> ByteStringUTF8 Source #

concatMap :: (Char -> ByteStringUTF8) -> ByteStringUTF8 -> ByteStringUTF8 Source #

toString :: (ByteStringUTF8 -> String) -> ByteStringUTF8 -> String Source #

any :: (Char -> Bool) -> ByteStringUTF8 -> Bool Source #

all :: (Char -> Bool) -> ByteStringUTF8 -> Bool Source #

foldl :: (a -> ByteStringUTF8 -> a) -> (a -> Char -> a) -> a -> ByteStringUTF8 -> a Source #

foldl' :: (a -> ByteStringUTF8 -> a) -> (a -> Char -> a) -> a -> ByteStringUTF8 -> a Source #

foldr :: (ByteStringUTF8 -> a -> a) -> (Char -> a -> a) -> a -> ByteStringUTF8 -> a Source #

scanl :: (Char -> Char -> Char) -> Char -> ByteStringUTF8 -> ByteStringUTF8 Source #

scanl1 :: (Char -> Char -> Char) -> ByteStringUTF8 -> ByteStringUTF8 Source #

scanr :: (Char -> Char -> Char) -> Char -> ByteStringUTF8 -> ByteStringUTF8 Source #

scanr1 :: (Char -> Char -> Char) -> ByteStringUTF8 -> ByteStringUTF8 Source #

mapAccumL :: (a -> Char -> (a, Char)) -> a -> ByteStringUTF8 -> (a, ByteStringUTF8) Source #

mapAccumR :: (a -> Char -> (a, Char)) -> a -> ByteStringUTF8 -> (a, ByteStringUTF8) Source #

takeWhile :: (ByteStringUTF8 -> Bool) -> (Char -> Bool) -> ByteStringUTF8 -> ByteStringUTF8 Source #

dropWhile :: (ByteStringUTF8 -> Bool) -> (Char -> Bool) -> ByteStringUTF8 -> ByteStringUTF8 Source #

break :: (ByteStringUTF8 -> Bool) -> (Char -> Bool) -> ByteStringUTF8 -> (ByteStringUTF8, ByteStringUTF8) Source #

span :: (ByteStringUTF8 -> Bool) -> (Char -> Bool) -> ByteStringUTF8 -> (ByteStringUTF8, ByteStringUTF8) Source #

spanMaybe :: s -> (s -> ByteStringUTF8 -> Maybe s) -> (s -> Char -> Maybe s) -> ByteStringUTF8 -> (ByteStringUTF8, ByteStringUTF8, s) Source #

spanMaybe' :: s -> (s -> ByteStringUTF8 -> Maybe s) -> (s -> Char -> Maybe s) -> ByteStringUTF8 -> (ByteStringUTF8, ByteStringUTF8, s) Source #

split :: (Char -> Bool) -> ByteStringUTF8 -> [ByteStringUTF8] Source #

find :: (Char -> Bool) -> ByteStringUTF8 -> Maybe Char Source #

elem :: Char -> ByteStringUTF8 -> Bool Source #

foldl_ :: (a -> Char -> a) -> a -> ByteStringUTF8 -> a Source #

foldl_' :: (a -> Char -> a) -> a -> ByteStringUTF8 -> a Source #

foldr_ :: (Char -> a -> a) -> a -> ByteStringUTF8 -> a Source #

takeWhile_ :: Bool -> (Char -> Bool) -> ByteStringUTF8 -> ByteStringUTF8 Source #

dropWhile_ :: Bool -> (Char -> Bool) -> ByteStringUTF8 -> ByteStringUTF8 Source #

break_ :: Bool -> (Char -> Bool) -> ByteStringUTF8 -> (ByteStringUTF8, ByteStringUTF8) Source #

span_ :: Bool -> (Char -> Bool) -> ByteStringUTF8 -> (ByteStringUTF8, ByteStringUTF8) Source #

spanMaybe_ :: s -> (s -> Char -> Maybe s) -> ByteStringUTF8 -> (ByteStringUTF8, ByteStringUTF8, s) Source #

spanMaybe_' :: s -> (s -> Char -> Maybe s) -> ByteStringUTF8 -> (ByteStringUTF8, ByteStringUTF8, s) Source #

decode :: ByteString -> (ByteStringUTF8, ByteString) Source #

Takes a raw ByteString chunk and returns a pair of ByteStringUTF8 decoding the prefix of the chunk and the remaining suffix that is either null or contains the incomplete last character of the chunk.