monoid-subclasses-1.2.4.1: Subclasses of Monoid

Safe Haskell | Safe-Inferred
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 #

Constructors

ByteStringUTF8 ByteString |

#### Instances

Instances details

Data ByteStringUTF8 # |
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 gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c ByteStringUTF8 toConstr :: ByteStringUTF8 -> Constr dataTypeOf :: ByteStringUTF8 -> DataType dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c ByteStringUTF8) dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ByteStringUTF8) gmapT :: (forall b. Data b => b -> b) -> ByteStringUTF8 -> ByteStringUTF8 gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> ByteStringUTF8 -> r gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> ByteStringUTF8 -> r gmapQ :: (forall d. Data d => d -> u) -> ByteStringUTF8 -> [u] gmapQi :: Int -> (forall d. Data d => d -> u) -> ByteStringUTF8 -> u gmapM :: Monad m => (forall d. Data d => d -> m d) -> ByteStringUTF8 -> m ByteStringUTF8 gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> ByteStringUTF8 -> m ByteStringUTF8 gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> ByteStringUTF8 -> m ByteStringUTF8
IsString ByteStringUTF8 # |
Instance details Defined in Data.Monoid.Instances.ByteString.UTF8 Methods fromString :: String -> ByteStringUTF8
Monoid ByteStringUTF8 # | O(n)
Instance details Defined in Data.Monoid.Instances.ByteString.UTF8 Methods mempty :: ByteStringUTF8 mappend :: ByteStringUTF8 -> ByteStringUTF8 -> ByteStringUTF8 mconcat :: [ByteStringUTF8] -> ByteStringUTF8
Semigroup ByteStringUTF8 # | O(n)
Instance details Defined in Data.Monoid.Instances.ByteString.UTF8 Methods (<>) :: ByteStringUTF8 -> ByteStringUTF8 -> ByteStringUTF8 sconcat :: NonEmpty ByteStringUTF8 -> ByteStringUTF8 stimes :: Integral b => b -> ByteStringUTF8 -> ByteStringUTF8
Show ByteStringUTF8 # |
Instance details Defined in Data.Monoid.Instances.ByteString.UTF8 Methods showsPrec :: Int -> ByteStringUTF8 -> ShowS show :: ByteStringUTF8 -> String showList :: [ByteStringUTF8] -> ShowS
Eq ByteStringUTF8 # |
Instance details Defined in Data.Monoid.Instances.ByteString.UTF8 Methods (==) :: ByteStringUTF8 -> ByteStringUTF8 -> Bool (/=) :: ByteStringUTF8 -> ByteStringUTF8 -> Bool
Ord ByteStringUTF8 # |
Instance details Defined in Data.Monoid.Instances.ByteString.UTF8 Methods compare :: ByteStringUTF8 -> ByteStringUTF8 -> Ordering (<) :: ByteStringUTF8 -> ByteStringUTF8 -> Bool (<=) :: ByteStringUTF8 -> ByteStringUTF8 -> Bool (>) :: ByteStringUTF8 -> ByteStringUTF8 -> Bool (>=) :: ByteStringUTF8 -> ByteStringUTF8 -> Bool max :: ByteStringUTF8 -> ByteStringUTF8 -> ByteStringUTF8 min :: ByteStringUTF8 -> ByteStringUTF8 -> ByteStringUTF8
FactorialMonoid ByteStringUTF8 # |
Instance details Defined in Data.Monoid.Instances.ByteString.UTF8 Methods splitPrimePrefix :: ByteStringUTF8 -> Maybe (ByteStringUTF8, ByteStringUTF8) # splitPrimeSuffix :: ByteStringUTF8 -> Maybe (ByteStringUTF8, ByteStringUTF8) # inits :: ByteStringUTF8 -> [ByteStringUTF8] # tails :: ByteStringUTF8 -> [ByteStringUTF8] # span :: (ByteStringUTF8 -> Bool) -> ByteStringUTF8 -> (ByteStringUTF8, ByteStringUTF8) # break :: (ByteStringUTF8 -> Bool) -> ByteStringUTF8 -> (ByteStringUTF8, ByteStringUTF8) # split :: (ByteStringUTF8 -> Bool) -> ByteStringUTF8 -> [ByteStringUTF8] # takeWhile :: (ByteStringUTF8 -> Bool) -> ByteStringUTF8 -> ByteStringUTF8 # dropWhile :: (ByteStringUTF8 -> Bool) -> ByteStringUTF8 -> ByteStringUTF8 # spanMaybe :: s -> (s -> ByteStringUTF8 -> Maybe s) -> ByteStringUTF8 -> (ByteStringUTF8, ByteStringUTF8, s) # spanMaybe' :: s -> (s -> ByteStringUTF8 -> Maybe s) -> ByteStringUTF8 -> (ByteStringUTF8, ByteStringUTF8, s) # splitAt :: Int -> ByteStringUTF8 -> (ByteStringUTF8, ByteStringUTF8) # drop :: Int -> ByteStringUTF8 -> ByteStringUTF8 # take :: Int -> ByteStringUTF8 -> ByteStringUTF8 #
LeftGCDMonoid ByteStringUTF8 # | O(prefixLength)
Instance details Defined in Data.Monoid.Instances.ByteString.UTF8 Methods commonPrefix :: ByteStringUTF8 -> ByteStringUTF8 -> ByteStringUTF8 # stripCommonPrefix :: ByteStringUTF8 -> ByteStringUTF8 -> (ByteStringUTF8, ByteStringUTF8, ByteStringUTF8) #
MonoidNull ByteStringUTF8 # | O(1)
Instance details Defined in Data.Monoid.Instances.ByteString.UTF8 Methods null :: ByteStringUTF8 -> Bool #
PositiveMonoid ByteStringUTF8 # |
Instance details Defined in Data.Monoid.Instances.ByteString.UTF8
TextualMonoid ByteStringUTF8 # |
Instance details Defined in Data.Monoid.Instances.ByteString.UTF8 Methods fromText :: Text -> ByteStringUTF8 # singleton :: Char -> ByteStringUTF8 # splitCharacterPrefix :: ByteStringUTF8 -> Maybe (Char, ByteStringUTF8) # characterPrefix :: ByteStringUTF8 -> Maybe Char # map :: (Char -> Char) -> ByteStringUTF8 -> ByteStringUTF8 # concatMap :: (Char -> ByteStringUTF8) -> ByteStringUTF8 -> ByteStringUTF8 # toString :: (ByteStringUTF8 -> String) -> ByteStringUTF8 -> String # toText :: (ByteStringUTF8 -> Text) -> ByteStringUTF8 -> Text # any :: (Char -> Bool) -> ByteStringUTF8 -> Bool # all :: (Char -> Bool) -> ByteStringUTF8 -> Bool # foldl :: (a -> ByteStringUTF8 -> a) -> (a -> Char -> a) -> a -> ByteStringUTF8 -> a # foldl' :: (a -> ByteStringUTF8 -> a) -> (a -> Char -> a) -> a -> ByteStringUTF8 -> a # foldr :: (ByteStringUTF8 -> a -> a) -> (Char -> a -> a) -> a -> ByteStringUTF8 -> a # scanl :: (Char -> Char -> Char) -> Char -> ByteStringUTF8 -> ByteStringUTF8 # scanl1 :: (Char -> Char -> Char) -> ByteStringUTF8 -> ByteStringUTF8 # scanr :: (Char -> Char -> Char) -> Char -> ByteStringUTF8 -> ByteStringUTF8 # scanr1 :: (Char -> Char -> Char) -> ByteStringUTF8 -> ByteStringUTF8 # mapAccumL :: (a -> Char -> (a, Char)) -> a -> ByteStringUTF8 -> (a, ByteStringUTF8) # mapAccumR :: (a -> Char -> (a, Char)) -> a -> ByteStringUTF8 -> (a, ByteStringUTF8) # takeWhile :: (ByteStringUTF8 -> Bool) -> (Char -> Bool) -> ByteStringUTF8 -> ByteStringUTF8 # dropWhile :: (ByteStringUTF8 -> Bool) -> (Char -> Bool) -> ByteStringUTF8 -> ByteStringUTF8 # break :: (ByteStringUTF8 -> Bool) -> (Char -> Bool) -> ByteStringUTF8 -> (ByteStringUTF8, ByteStringUTF8) # span :: (ByteStringUTF8 -> Bool) -> (Char -> Bool) -> ByteStringUTF8 -> (ByteStringUTF8, ByteStringUTF8) # spanMaybe :: s -> (s -> ByteStringUTF8 -> Maybe s) -> (s -> Char -> Maybe s) -> ByteStringUTF8 -> (ByteStringUTF8, ByteStringUTF8, s) # spanMaybe' :: s -> (s -> ByteStringUTF8 -> Maybe s) -> (s -> Char -> Maybe s) -> ByteStringUTF8 -> (ByteStringUTF8, ByteStringUTF8, s) # split :: (Char -> Bool) -> ByteStringUTF8 -> [ByteStringUTF8] # find :: (Char -> Bool) -> ByteStringUTF8 -> Maybe Char # elem :: Char -> ByteStringUTF8 -> Bool # foldl_ :: (a -> Char -> a) -> a -> ByteStringUTF8 -> a # foldl_' :: (a -> Char -> a) -> a -> ByteStringUTF8 -> a # foldr_ :: (Char -> a -> a) -> a -> ByteStringUTF8 -> a # takeWhile_ :: Bool -> (Char -> Bool) -> ByteStringUTF8 -> ByteStringUTF8 # dropWhile_ :: Bool -> (Char -> Bool) -> ByteStringUTF8 -> ByteStringUTF8 # break_ :: Bool -> (Char -> Bool) -> ByteStringUTF8 -> (ByteStringUTF8, ByteStringUTF8) # span_ :: Bool -> (Char -> Bool) -> ByteStringUTF8 -> (ByteStringUTF8, ByteStringUTF8) # spanMaybe_ :: s -> (s -> Char -> Maybe s) -> ByteStringUTF8 -> (ByteStringUTF8, ByteStringUTF8, s) # spanMaybe_' :: s -> (s -> Char -> Maybe s) -> ByteStringUTF8 -> (ByteStringUTF8, ByteStringUTF8, s) #
LeftCancellative ByteStringUTF8 # |
Instance details Defined in Data.Monoid.Instances.ByteString.UTF8
LeftReductive ByteStringUTF8 # | O(n)
Instance details Defined in Data.Monoid.Instances.ByteString.UTF8 Methods isPrefixOf :: ByteStringUTF8 -> ByteStringUTF8 -> Bool # stripPrefix :: ByteStringUTF8 -> ByteStringUTF8 -> Maybe ByteStringUTF8 #
Factorial ByteStringUTF8 # |
Instance details Defined in Data.Monoid.Instances.ByteString.UTF8 Methods factors :: ByteStringUTF8 -> [ByteStringUTF8] # primePrefix :: ByteStringUTF8 -> ByteStringUTF8 # primeSuffix :: ByteStringUTF8 -> ByteStringUTF8 # foldl :: (a -> ByteStringUTF8 -> a) -> a -> ByteStringUTF8 -> a # foldl' :: (a -> ByteStringUTF8 -> a) -> a -> ByteStringUTF8 -> a # foldr :: (ByteStringUTF8 -> a -> a) -> a -> ByteStringUTF8 -> a # length :: ByteStringUTF8 -> Int # foldMap :: Monoid n => (ByteStringUTF8 -> n) -> ByteStringUTF8 -> n # reverse :: ByteStringUTF8 -> ByteStringUTF8 #

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

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.