monoid-subclasses-1.2.6: Subclasses of Monoid

Safe Haskell | None
Language | Haskell2010

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

- newtype ByteStringUTF8 = ByteStringUTF8 ByteString
- decode :: ByteString -> (ByteStringUTF8, ByteString)

# Documentation

newtype ByteStringUTF8 Source #

Constructors

ByteStringUTF8 ByteString |

#### Instances

Instances details

Monoid ByteStringUTF8 Source # | O(n)
Instance details Defined in Data.Monoid.Instances.ByteString.UTF8 Methods mempty :: ByteStringUTF8 Source # mappend :: ByteStringUTF8 -> ByteStringUTF8 -> ByteStringUTF8 Source # mconcat :: [ByteStringUTF8] -> ByteStringUTF8 Source #
Semigroup ByteStringUTF8 Source # | O(n)
Instance details Defined in Data.Monoid.Instances.ByteString.UTF8 Methods (<>) :: ByteStringUTF8 -> ByteStringUTF8 -> ByteStringUTF8 Source # sconcat :: NonEmpty ByteStringUTF8 -> ByteStringUTF8 Source # stimes :: Integral b => b -> ByteStringUTF8 -> ByteStringUTF8 Source #
Data ByteStringUTF8 Source # |

Instance details

Defined in Data.Monoid.Instances.ByteString.UTF8

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> ByteStringUTF8 -> c ByteStringUTF8 Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c ByteStringUTF8 Source #

toConstr :: ByteStringUTF8 -> Constr Source #

dataTypeOf :: ByteStringUTF8 -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c ByteStringUTF8) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ByteStringUTF8) Source #

gmapT :: (forall b. Data b => b -> b) -> ByteStringUTF8 -> ByteStringUTF8 Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> ByteStringUTF8 -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> ByteStringUTF8 -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> ByteStringUTF8 -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> ByteStringUTF8 -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> ByteStringUTF8 -> m ByteStringUTF8 Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> ByteStringUTF8 -> m ByteStringUTF8 Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> ByteStringUTF8 -> m ByteStringUTF8 Source #

IsString ByteStringUTF8 Source # |
Instance details Defined in Data.Monoid.Instances.ByteString.UTF8 Methods fromString :: String -> ByteStringUTF8 Source #
Show ByteStringUTF8 Source # |
Instance details Defined in Data.Monoid.Instances.ByteString.UTF8 Methods showsPrec :: Int -> ByteStringUTF8 -> ShowS Source # show :: ByteStringUTF8 -> String Source # showList :: [ByteStringUTF8] -> ShowS Source #
Eq ByteStringUTF8 Source # |
Instance details Defined in Data.Monoid.Instances.ByteString.UTF8 Methods (==) :: ByteStringUTF8 -> ByteStringUTF8 -> Bool Source # (/=) :: ByteStringUTF8 -> ByteStringUTF8 -> Bool Source #
Ord ByteStringUTF8 Source # |

Instance details

Defined in Data.Monoid.Instances.ByteString.UTF8

Methods

compare :: ByteStringUTF8 -> ByteStringUTF8 -> Ordering Source #

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

(<=) :: ByteStringUTF8 -> ByteStringUTF8 -> Bool Source #

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

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

max :: ByteStringUTF8 -> ByteStringUTF8 -> ByteStringUTF8 Source #

min :: ByteStringUTF8 -> ByteStringUTF8 -> ByteStringUTF8 Source #

FactorialMonoid ByteStringUTF8 Source # |

Instance details

Defined in Data.Monoid.Instances.ByteString.UTF8

Methods

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

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

inits :: ByteStringUTF8 -> [ByteStringUTF8] Source #

tails :: ByteStringUTF8 -> [ByteStringUTF8] 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 #

LeftGCDMonoid ByteStringUTF8 Source # | O(prefixLength)
Instance details Defined in Data.Monoid.Instances.ByteString.UTF8 Methods commonPrefix :: ByteStringUTF8 -> ByteStringUTF8 -> ByteStringUTF8 Source # stripCommonPrefix :: ByteStringUTF8 -> ByteStringUTF8 -> (ByteStringUTF8, ByteStringUTF8, ByteStringUTF8) Source #
MonoidNull ByteStringUTF8 Source # | O(1)
Instance details Defined in Data.Monoid.Instances.ByteString.UTF8 Methods null :: ByteStringUTF8 -> Bool Source #
PositiveMonoid ByteStringUTF8 Source # |
Instance details Defined in Data.Monoid.Instances.ByteString.UTF8
TextualMonoid ByteStringUTF8 Source # |

Instance details

Defined in Data.Monoid.Instances.ByteString.UTF8

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 #

toText :: (ByteStringUTF8 -> Text) -> ByteStringUTF8 -> Text 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 #

LeftCancellative ByteStringUTF8 Source # |
Instance details Defined in Data.Monoid.Instances.ByteString.UTF8
LeftReductive ByteStringUTF8 Source # | O(n)
Instance details Defined in Data.Monoid.Instances.ByteString.UTF8 Methods isPrefixOf :: ByteStringUTF8 -> ByteStringUTF8 -> Bool Source # stripPrefix :: ByteStringUTF8 -> ByteStringUTF8 -> Maybe ByteStringUTF8 Source #
Factorial ByteStringUTF8 Source # |

Instance details

Defined in Data.Monoid.Instances.ByteString.UTF8

Methods

factors :: ByteStringUTF8 -> [ByteStringUTF8] Source #

primePrefix :: ByteStringUTF8 -> ByteStringUTF8 Source #

primeSuffix :: 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 #

reverse :: ByteStringUTF8 -> ByteStringUTF8 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.