module TextBuilderDev
( TextBuilder,
buildText,
length,
null,
putToStdOut,
putToStdErr,
putLnToStdOut,
putLnToStdErr,
force,
intercalate,
intercalateMap,
padFromLeft,
padFromRight,
text,
lazyText,
string,
asciiByteString,
hexData,
char,
unicodeCodePoint,
utf16CodeUnits1,
utf16CodeUnits2,
utf8CodeUnits1,
utf8CodeUnits2,
utf8CodeUnits3,
utf8CodeUnits4,
decimal,
unsignedDecimal,
fixedUnsignedDecimal,
thousandSeparatedDecimal,
thousandSeparatedUnsignedDecimal,
dataSizeInBytesInDecimal,
unsignedBinary,
unsignedPaddedBinary,
finiteBitsUnsignedBinary,
hexadecimal,
unsignedHexadecimal,
decimalDigit,
hexadecimalDigit,
fixedDouble,
doublePercent,
utcTimeInIso8601,
utcTimestampInIso8601,
intervalInSeconds,
IsomorphicToTextBuilder (..),
)
where
import qualified Data.ByteString as ByteString
import qualified Data.List.Split as Split
import qualified Data.Text as Text
import qualified Data.Text.IO as Text
import qualified Data.Text.Lazy as TextLazy
import qualified Data.Text.Lazy.Builder as TextLazyBuilder
import qualified DeferredFolds.Unfoldr as Unfoldr
import qualified Test.QuickCheck.Gen as QcGen
import qualified TextBuilderDev.Allocator as Allocator
import TextBuilderDev.Prelude hiding (intercalate, length, null)
class IsomorphicToTextBuilder a where
toTextBuilder :: a -> TextBuilder
fromTextBuilder :: TextBuilder -> a
instance IsomorphicToTextBuilder TextBuilder where
toTextBuilder :: TextBuilder -> TextBuilder
toTextBuilder = forall {k} (cat :: k -> k -> *) (a :: k). Category cat => cat a a
id
fromTextBuilder :: TextBuilder -> TextBuilder
fromTextBuilder = forall {k} (cat :: k -> k -> *) (a :: k). Category cat => cat a a
id
instance IsomorphicToTextBuilder Text where
toTextBuilder :: Text -> TextBuilder
toTextBuilder = Text -> TextBuilder
text
fromTextBuilder :: TextBuilder -> Text
fromTextBuilder = TextBuilder -> Text
buildText
instance IsomorphicToTextBuilder String where
toTextBuilder :: String -> TextBuilder
toTextBuilder = forall a. IsString a => String -> a
fromString
fromTextBuilder :: TextBuilder -> String
fromTextBuilder = Text -> String
Text.unpack forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. TextBuilder -> Text
buildText
instance IsomorphicToTextBuilder TextLazy.Text where
toTextBuilder :: Text -> TextBuilder
toTextBuilder = Text -> TextBuilder
lazyText
fromTextBuilder :: TextBuilder -> Text
fromTextBuilder = Text -> Text
TextLazy.fromStrict forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. TextBuilder -> Text
buildText
instance IsomorphicToTextBuilder TextLazyBuilder.Builder where
toTextBuilder :: Builder -> TextBuilder
toTextBuilder = Text -> TextBuilder
text forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Text -> Text
TextLazy.toStrict forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Builder -> Text
TextLazyBuilder.toLazyText
fromTextBuilder :: TextBuilder -> Builder
fromTextBuilder = Text -> Builder
TextLazyBuilder.fromText forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. TextBuilder -> Text
buildText
data TextBuilder
= TextBuilder
{-# UNPACK #-} !Allocator.Allocator
{-# UNPACK #-} !Int
instance Semigroup TextBuilder where
<> :: TextBuilder -> TextBuilder -> TextBuilder
(<>) (TextBuilder Allocator
allocator1 Int
sizeInChars1) (TextBuilder Allocator
allocator2 Int
sizeInChars2) =
Allocator -> Int -> TextBuilder
TextBuilder
(Allocator
allocator1 forall a. Semigroup a => a -> a -> a
<> Allocator
allocator2)
(Int
sizeInChars1 forall a. Num a => a -> a -> a
+ Int
sizeInChars2)
stimes :: forall b. Integral b => b -> TextBuilder -> TextBuilder
stimes b
n (TextBuilder Allocator
allocator Int
size) =
Allocator -> Int -> TextBuilder
TextBuilder (forall a b. (Semigroup a, Integral b) => b -> a -> a
stimes b
n Allocator
allocator) (Int
size forall a. Num a => a -> a -> a
* forall a b. (Integral a, Num b) => a -> b
fromIntegral b
n)
instance Monoid TextBuilder where
{-# INLINE mempty #-}
mempty :: TextBuilder
mempty = Allocator -> Int -> TextBuilder
TextBuilder forall a. Monoid a => a
mempty Int
0
instance IsString TextBuilder where
fromString :: String -> TextBuilder
fromString = String -> TextBuilder
string
instance Show TextBuilder where
show :: TextBuilder -> String
show = Text -> String
Text.unpack forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. TextBuilder -> Text
buildText
instance Eq TextBuilder where
== :: TextBuilder -> TextBuilder -> Bool
(==) = forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
on forall a. Eq a => a -> a -> Bool
(==) TextBuilder -> Text
buildText
instance Arbitrary TextBuilder where
arbitrary :: Gen TextBuilder
arbitrary =
forall a. [Gen a] -> Gen a
QcGen.oneof
[ forall a. (Int -> Int) -> Gen a -> Gen a
QcGen.scale (forall a b c. (a -> b -> c) -> b -> a -> c
flip forall a. Integral a => a -> a -> a
div Int
2)
forall a b. (a -> b) -> a -> b
$ forall a. [Gen a] -> Gen a
QcGen.oneof
[ forall a. Semigroup a => a -> a -> a
(<>) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary,
forall a. Semigroup a => NonEmpty a -> a
sconcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary,
forall a b. (Semigroup a, Integral b) => b -> a -> a
stimes forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary @Word8 forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary,
forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a. Monoid a => a
mempty,
forall a. Monoid a => [a] -> a
mconcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary
],
Text -> TextBuilder
text forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary,
Text -> TextBuilder
lazyText forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary,
String -> TextBuilder
string forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary,
ByteString -> TextBuilder
asciiByteString forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. (Word8 -> Bool) -> ByteString -> ByteString
ByteString.filter (forall a. Ord a => a -> a -> Bool
< Word8
128) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary,
ByteString -> TextBuilder
hexData forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary,
Char -> TextBuilder
char forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary,
forall a. Integral a => a -> TextBuilder
decimal @Integer forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary,
forall a. Integral a => a -> TextBuilder
unsignedDecimal @Natural forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary,
forall a. Integral a => Char -> a -> TextBuilder
thousandSeparatedDecimal @Integer forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary,
forall a. Integral a => Char -> a -> TextBuilder
thousandSeparatedUnsignedDecimal @Natural forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary,
forall a. Integral a => Char -> a -> TextBuilder
dataSizeInBytesInDecimal @Natural forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary,
forall a. Integral a => a -> TextBuilder
unsignedBinary @Natural forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary,
forall a. (Integral a, FiniteBits a) => a -> TextBuilder
unsignedPaddedBinary @Word forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary,
forall a. FiniteBits a => a -> TextBuilder
finiteBitsUnsignedBinary @Word forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary,
forall a. Integral a => a -> TextBuilder
hexadecimal @Integer forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary,
forall a. Integral a => a -> TextBuilder
unsignedHexadecimal @Natural forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary,
forall a. Integral a => a -> TextBuilder
decimalDigit forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Random a => (a, a) -> Gen a
QcGen.choose @Int (Int
0, Int
9),
forall a. Integral a => a -> TextBuilder
hexadecimalDigit forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Random a => (a, a) -> Gen a
QcGen.choose @Int (Int
0, Int
15),
Int -> Double -> TextBuilder
fixedDouble forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Random a => (a, a) -> Gen a
QcGen.choose (Int
0, Int
19) forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary,
Int -> Double -> TextBuilder
doublePercent forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Random a => (a, a) -> Gen a
QcGen.choose (Int
0, Int
19) forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary,
Int -> Int -> Int -> Int -> Int -> Int -> TextBuilder
utcTimestampInIso8601 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary,
forall seconds. RealFrac seconds => seconds -> TextBuilder
intervalInSeconds @Double forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary
]
instance IsomorphicTo TextBuilder TextBuilder where
to :: TextBuilder -> TextBuilder
to = forall {k} (cat :: k -> k -> *) (a :: k). Category cat => cat a a
id
instance IsomorphicTo TextBuilder String where
to :: String -> TextBuilder
to = String -> TextBuilder
TextBuilderDev.string
instance IsomorphicTo TextBuilder Text where
to :: Text -> TextBuilder
to = Text -> TextBuilder
TextBuilderDev.text
instance IsomorphicTo TextBuilder TextLazy.Text where
to :: Text -> TextBuilder
to = Text -> TextBuilder
TextBuilderDev.lazyText
instance IsomorphicTo TextBuilder TextLazyBuilder.Builder where
to :: Builder -> TextBuilder
to = forall a b. IsomorphicTo a b => b -> a
to forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a b. IsomorphicTo a b => b -> a
to @TextLazy.Text
instance IsomorphicTo String TextBuilder where
to :: TextBuilder -> String
to = forall a b. IsomorphicTo a b => b -> a
to forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a b. IsomorphicTo a b => b -> a
to @Text
instance IsomorphicTo Text TextBuilder where
to :: TextBuilder -> Text
to = TextBuilder -> Text
TextBuilderDev.buildText
instance IsomorphicTo TextLazy.Text TextBuilder where
to :: TextBuilder -> Text
to = forall a b. IsomorphicTo a b => b -> a
to forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a b. IsomorphicTo a b => b -> a
to @Text
instance IsomorphicTo TextLazyBuilder.Builder TextBuilder where
to :: TextBuilder -> Builder
to = forall a b. IsomorphicTo a b => b -> a
to forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a b. IsomorphicTo a b => b -> a
to @Text
{-# INLINE length #-}
length :: TextBuilder -> Int
length :: TextBuilder -> Int
length (TextBuilder Allocator
_ Int
x) = Int
x
{-# INLINE null #-}
null :: TextBuilder -> Bool
null :: TextBuilder -> Bool
null = (forall a. Eq a => a -> a -> Bool
== Int
0) forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. TextBuilder -> Int
length
buildText :: TextBuilder -> Text
buildText :: TextBuilder -> Text
buildText (TextBuilder Allocator
allocator Int
_) =
Allocator -> Text
Allocator.allocate Allocator
allocator
putToStdOut :: TextBuilder -> IO ()
putToStdOut :: TextBuilder -> IO ()
putToStdOut = Handle -> Text -> IO ()
Text.hPutStr Handle
stdout forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. TextBuilder -> Text
buildText
putToStdErr :: TextBuilder -> IO ()
putToStdErr :: TextBuilder -> IO ()
putToStdErr = Handle -> Text -> IO ()
Text.hPutStr Handle
stderr forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. TextBuilder -> Text
buildText
putLnToStdOut :: TextBuilder -> IO ()
putLnToStdOut :: TextBuilder -> IO ()
putLnToStdOut = Handle -> Text -> IO ()
Text.hPutStrLn Handle
stdout forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. TextBuilder -> Text
buildText
putLnToStdErr :: TextBuilder -> IO ()
putLnToStdErr :: TextBuilder -> IO ()
putLnToStdErr = Handle -> Text -> IO ()
Text.hPutStrLn Handle
stderr forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. TextBuilder -> Text
buildText
{-# INLINE force #-}
force :: TextBuilder -> TextBuilder
force :: TextBuilder -> TextBuilder
force = Text -> TextBuilder
text forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. TextBuilder -> Text
buildText
{-# INLINE char #-}
char :: Char -> TextBuilder
char :: Char -> TextBuilder
char = Int -> TextBuilder
unicodeCodePoint forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Char -> Int
ord
{-# INLINE unicodeCodePoint #-}
unicodeCodePoint :: Int -> TextBuilder
unicodeCodePoint :: Int -> TextBuilder
unicodeCodePoint Int
a =
Allocator -> Int -> TextBuilder
TextBuilder (Int -> Allocator
Allocator.unicodeCodePoint Int
a) Int
1
{-# INLINEABLE utf16CodeUnits1 #-}
utf16CodeUnits1 :: Word16 -> TextBuilder
utf16CodeUnits1 :: Word16 -> TextBuilder
utf16CodeUnits1 Word16
a =
Allocator -> Int -> TextBuilder
TextBuilder (Word16 -> Allocator
Allocator.utf16CodeUnits1 Word16
a) Int
1
{-# INLINEABLE utf16CodeUnits2 #-}
utf16CodeUnits2 :: Word16 -> Word16 -> TextBuilder
utf16CodeUnits2 :: Word16 -> Word16 -> TextBuilder
utf16CodeUnits2 Word16
a Word16
b =
Allocator -> Int -> TextBuilder
TextBuilder (Word16 -> Word16 -> Allocator
Allocator.utf16CodeUnits2 Word16
a Word16
b) Int
1
{-# INLINE utf8CodeUnits1 #-}
utf8CodeUnits1 :: Word8 -> TextBuilder
utf8CodeUnits1 :: Word8 -> TextBuilder
utf8CodeUnits1 Word8
a =
Allocator -> Int -> TextBuilder
TextBuilder (Word8 -> Allocator
Allocator.utf8CodeUnits1 Word8
a) Int
1
{-# INLINE utf8CodeUnits2 #-}
utf8CodeUnits2 :: Word8 -> Word8 -> TextBuilder
utf8CodeUnits2 :: Word8 -> Word8 -> TextBuilder
utf8CodeUnits2 Word8
a Word8
b =
Allocator -> Int -> TextBuilder
TextBuilder (Word8 -> Word8 -> Allocator
Allocator.utf8CodeUnits2 Word8
a Word8
b) Int
1
{-# INLINE utf8CodeUnits3 #-}
utf8CodeUnits3 :: Word8 -> Word8 -> Word8 -> TextBuilder
utf8CodeUnits3 :: Word8 -> Word8 -> Word8 -> TextBuilder
utf8CodeUnits3 Word8
a Word8
b Word8
c =
Allocator -> Int -> TextBuilder
TextBuilder (Word8 -> Word8 -> Word8 -> Allocator
Allocator.utf8CodeUnits3 Word8
a Word8
b Word8
c) Int
1
{-# INLINE utf8CodeUnits4 #-}
utf8CodeUnits4 :: Word8 -> Word8 -> Word8 -> Word8 -> TextBuilder
utf8CodeUnits4 :: Word8 -> Word8 -> Word8 -> Word8 -> TextBuilder
utf8CodeUnits4 Word8
a Word8
b Word8
c Word8
d =
Allocator -> Int -> TextBuilder
TextBuilder (Word8 -> Word8 -> Word8 -> Word8 -> Allocator
Allocator.utf8CodeUnits4 Word8
a Word8
b Word8
c Word8
d) Int
1
{-# INLINEABLE asciiByteString #-}
asciiByteString :: ByteString -> TextBuilder
asciiByteString :: ByteString -> TextBuilder
asciiByteString ByteString
byteString =
Allocator -> Int -> TextBuilder
TextBuilder
(ByteString -> Allocator
Allocator.asciiByteString ByteString
byteString)
(ByteString -> Int
ByteString.length ByteString
byteString)
{-# INLINEABLE text #-}
text :: Text -> TextBuilder
text :: Text -> TextBuilder
text Text
text =
Allocator -> Int -> TextBuilder
TextBuilder (Text -> Allocator
Allocator.text Text
text) (Text -> Int
Text.length Text
text)
{-# INLINE lazyText #-}
lazyText :: TextLazy.Text -> TextBuilder
lazyText :: Text -> TextBuilder
lazyText =
forall a. (Text -> a -> a) -> a -> Text -> a
TextLazy.foldrChunks (forall a. Monoid a => a -> a -> a
mappend forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Text -> TextBuilder
text) forall a. Monoid a => a
mempty
{-# INLINE string #-}
string :: String -> TextBuilder
string :: String -> TextBuilder
string =
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap Char -> TextBuilder
char
{-# INLINEABLE decimal #-}
decimal :: (Integral a) => a -> TextBuilder
decimal :: forall a. Integral a => a -> TextBuilder
decimal a
i =
if a
i forall a. Ord a => a -> a -> Bool
>= a
0
then forall a. Integral a => a -> TextBuilder
unsignedDecimal a
i
else Int -> TextBuilder
unicodeCodePoint Int
45 forall a. Semigroup a => a -> a -> a
<> forall a. Integral a => a -> TextBuilder
unsignedDecimal (forall a. Num a => a -> a
negate a
i)
{-# INLINEABLE unsignedDecimal #-}
unsignedDecimal :: (Integral a) => a -> TextBuilder
unsignedDecimal :: forall a. Integral a => a -> TextBuilder
unsignedDecimal =
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (forall a. Integral a => a -> TextBuilder
decimalDigit forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a b. (Integral a, Num b) => a -> b
fromIntegral) forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a. Integral a => a -> Unfoldr a
Unfoldr.decimalDigits
fixedUnsignedDecimal :: (Integral a) => Int -> a -> TextBuilder
fixedUnsignedDecimal :: forall a. Integral a => Int -> a -> TextBuilder
fixedUnsignedDecimal Int
size a
val =
Allocator -> Int -> TextBuilder
TextBuilder (forall a. Integral a => Int -> a -> Allocator
Allocator.fixedUnsignedDecimal Int
size a
val) Int
size
{-# INLINEABLE thousandSeparatedDecimal #-}
thousandSeparatedDecimal :: (Integral a) => Char -> a -> TextBuilder
thousandSeparatedDecimal :: forall a. Integral a => Char -> a -> TextBuilder
thousandSeparatedDecimal Char
separatorChar a
a =
if a
a forall a. Ord a => a -> a -> Bool
>= a
0
then forall a. Integral a => Char -> a -> TextBuilder
thousandSeparatedUnsignedDecimal Char
separatorChar a
a
else Int -> TextBuilder
unicodeCodePoint Int
45 forall a. Semigroup a => a -> a -> a
<> forall a. Integral a => Char -> a -> TextBuilder
thousandSeparatedUnsignedDecimal Char
separatorChar (forall a. Num a => a -> a
negate a
a)
{-# INLINEABLE thousandSeparatedUnsignedDecimal #-}
thousandSeparatedUnsignedDecimal :: (Integral a) => Char -> a -> TextBuilder
thousandSeparatedUnsignedDecimal :: forall a. Integral a => Char -> a -> TextBuilder
thousandSeparatedUnsignedDecimal Char
separatorChar =
a -> TextBuilder
processRightmostDigit
where
processRightmostDigit :: a -> TextBuilder
processRightmostDigit a
value =
case forall a. Integral a => a -> a -> (a, a)
divMod a
value a
10 of
(a
value, a
digit) ->
[TextBuilder] -> Year -> a -> TextBuilder
processAnotherDigit [forall a. Integral a => a -> TextBuilder
decimalDigit (forall a b. (Integral a, Num b) => a -> b
fromIntegral a
digit)] Year
1 a
value
processAnotherDigit :: [TextBuilder] -> Year -> a -> TextBuilder
processAnotherDigit [TextBuilder]
builders Year
index a
value =
if a
value forall a. Eq a => a -> a -> Bool
== a
0
then forall a. Monoid a => [a] -> a
mconcat [TextBuilder]
builders
else case forall a. Integral a => a -> a -> (a, a)
divMod a
value a
10 of
(a
value, a
digit) ->
if forall a. Integral a => a -> a -> a
mod Year
index Year
3 forall a. Eq a => a -> a -> Bool
== Year
0
then
[TextBuilder] -> Year -> a -> TextBuilder
processAnotherDigit
(forall a. Integral a => a -> TextBuilder
decimalDigit (forall a b. (Integral a, Num b) => a -> b
fromIntegral a
digit) forall a. a -> [a] -> [a]
: Char -> TextBuilder
char Char
separatorChar forall a. a -> [a] -> [a]
: [TextBuilder]
builders)
(forall a. Enum a => a -> a
succ Year
index)
a
value
else
[TextBuilder] -> Year -> a -> TextBuilder
processAnotherDigit
(forall a. Integral a => a -> TextBuilder
decimalDigit (forall a b. (Integral a, Num b) => a -> b
fromIntegral a
digit) forall a. a -> [a] -> [a]
: [TextBuilder]
builders)
(forall a. Enum a => a -> a
succ Year
index)
a
value
{-# INLINEABLE dataSizeInBytesInDecimal #-}
dataSizeInBytesInDecimal :: (Integral a) => Char -> a -> TextBuilder
dataSizeInBytesInDecimal :: forall a. Integral a => Char -> a -> TextBuilder
dataSizeInBytesInDecimal Char
separatorChar a
amount =
if a
amount forall a. Ord a => a -> a -> Bool
< a
1000
then forall a. Integral a => a -> TextBuilder
unsignedDecimal a
amount forall a. Semigroup a => a -> a -> a
<> TextBuilder
"B"
else
if a
amount forall a. Ord a => a -> a -> Bool
< a
1000000
then forall a. Integral a => Char -> a -> a -> TextBuilder
dividedDecimal Char
separatorChar a
100 a
amount forall a. Semigroup a => a -> a -> a
<> TextBuilder
"kB"
else
if a
amount forall a. Ord a => a -> a -> Bool
< a
1000000000
then forall a. Integral a => Char -> a -> a -> TextBuilder
dividedDecimal Char
separatorChar a
100000 a
amount forall a. Semigroup a => a -> a -> a
<> TextBuilder
"MB"
else
if a
amount forall a. Ord a => a -> a -> Bool
< a
1000000000000
then forall a. Integral a => Char -> a -> a -> TextBuilder
dividedDecimal Char
separatorChar a
100000000 a
amount forall a. Semigroup a => a -> a -> a
<> TextBuilder
"GB"
else
if a
amount forall a. Ord a => a -> a -> Bool
< a
1000000000000000
then forall a. Integral a => Char -> a -> a -> TextBuilder
dividedDecimal Char
separatorChar a
100000000000 a
amount forall a. Semigroup a => a -> a -> a
<> TextBuilder
"TB"
else
if a
amount forall a. Ord a => a -> a -> Bool
< a
1000000000000000000
then forall a. Integral a => Char -> a -> a -> TextBuilder
dividedDecimal Char
separatorChar a
100000000000000 a
amount forall a. Semigroup a => a -> a -> a
<> TextBuilder
"PB"
else
if a
amount forall a. Ord a => a -> a -> Bool
< a
1000000000000000000000
then forall a. Integral a => Char -> a -> a -> TextBuilder
dividedDecimal Char
separatorChar a
100000000000000000 a
amount forall a. Semigroup a => a -> a -> a
<> TextBuilder
"EB"
else
if a
amount forall a. Ord a => a -> a -> Bool
< a
1000000000000000000000000
then forall a. Integral a => Char -> a -> a -> TextBuilder
dividedDecimal Char
separatorChar a
100000000000000000000 a
amount forall a. Semigroup a => a -> a -> a
<> TextBuilder
"ZB"
else forall a. Integral a => Char -> a -> a -> TextBuilder
dividedDecimal Char
separatorChar a
100000000000000000000000 a
amount forall a. Semigroup a => a -> a -> a
<> TextBuilder
"YB"
dividedDecimal :: (Integral a) => Char -> a -> a -> TextBuilder
dividedDecimal :: forall a. Integral a => Char -> a -> a -> TextBuilder
dividedDecimal Char
separatorChar a
divisor a
n =
let byDivisor :: a
byDivisor = forall a. Integral a => a -> a -> a
div a
n a
divisor
byExtraTen :: a
byExtraTen = forall a. Integral a => a -> a -> a
div a
byDivisor a
10
remainder :: a
remainder = a
byDivisor forall a. Num a => a -> a -> a
- a
byExtraTen forall a. Num a => a -> a -> a
* a
10
in if a
remainder forall a. Eq a => a -> a -> Bool
== a
0 Bool -> Bool -> Bool
|| a
byExtraTen forall a. Ord a => a -> a -> Bool
>= a
10
then forall a. Integral a => Char -> a -> TextBuilder
thousandSeparatedDecimal Char
separatorChar a
byExtraTen
else forall a. Integral a => Char -> a -> TextBuilder
thousandSeparatedDecimal Char
separatorChar a
byExtraTen forall a. Semigroup a => a -> a -> a
<> TextBuilder
"." forall a. Semigroup a => a -> a -> a
<> forall a. Integral a => a -> TextBuilder
decimalDigit (forall a b. (Integral a, Num b) => a -> b
fromIntegral a
remainder)
{-# INLINE unsignedBinary #-}
unsignedBinary :: (Integral a) => a -> TextBuilder
unsignedBinary :: forall a. Integral a => a -> TextBuilder
unsignedBinary =
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (forall a. Integral a => a -> TextBuilder
decimalDigit forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a b. (Integral a, Num b) => a -> b
fromIntegral) forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a. Integral a => a -> Unfoldr a
Unfoldr.binaryDigits
finiteBitsUnsignedBinary :: (FiniteBits a) => a -> TextBuilder
finiteBitsUnsignedBinary :: forall a. FiniteBits a => a -> TextBuilder
finiteBitsUnsignedBinary a
a =
Allocator -> Int -> TextBuilder
TextBuilder Allocator
allocator Int
size
where
allocator :: Allocator
allocator = forall a. FiniteBits a => a -> Allocator
Allocator.finiteBitsUnsignedBinary a
a
size :: Int
size = Allocator -> Int
Allocator.sizeBound Allocator
allocator
{-# INLINE unsignedPaddedBinary #-}
unsignedPaddedBinary :: (Integral a, FiniteBits a) => a -> TextBuilder
unsignedPaddedBinary :: forall a. (Integral a, FiniteBits a) => a -> TextBuilder
unsignedPaddedBinary a
a =
Int -> Char -> TextBuilder -> TextBuilder
padFromLeft (forall b. FiniteBits b => b -> Int
finiteBitSize a
a) Char
'0' forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (forall a. Integral a => a -> TextBuilder
decimalDigit forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a b. (Integral a, Num b) => a -> b
fromIntegral) forall a b. (a -> b) -> a -> b
$ forall a. Integral a => a -> Unfoldr a
Unfoldr.binaryDigits a
a
{-# INLINE hexadecimal #-}
hexadecimal :: (Integral a) => a -> TextBuilder
hexadecimal :: forall a. Integral a => a -> TextBuilder
hexadecimal a
i =
if a
i forall a. Ord a => a -> a -> Bool
>= a
0
then forall a. Integral a => a -> TextBuilder
unsignedHexadecimal a
i
else Int -> TextBuilder
unicodeCodePoint Int
45 forall a. Semigroup a => a -> a -> a
<> forall a. Integral a => a -> TextBuilder
unsignedHexadecimal (forall a. Num a => a -> a
negate a
i)
{-# INLINE unsignedHexadecimal #-}
unsignedHexadecimal :: (Integral a) => a -> TextBuilder
unsignedHexadecimal :: forall a. Integral a => a -> TextBuilder
unsignedHexadecimal =
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (forall a. Integral a => a -> TextBuilder
hexadecimalDigit forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a b. (Integral a, Num b) => a -> b
fromIntegral) forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a. Integral a => a -> Unfoldr a
Unfoldr.hexadecimalDigits
{-# INLINE decimalDigit #-}
decimalDigit :: (Integral a) => a -> TextBuilder
decimalDigit :: forall a. Integral a => a -> TextBuilder
decimalDigit (forall a b. (Integral a, Num b) => a -> b
fromIntegral -> Int
n) =
Int -> TextBuilder
unicodeCodePoint (Int
n forall a. Num a => a -> a -> a
+ Int
48)
{-# INLINE hexadecimalDigit #-}
hexadecimalDigit :: (Integral a) => a -> TextBuilder
hexadecimalDigit :: forall a. Integral a => a -> TextBuilder
hexadecimalDigit (forall a b. (Integral a, Num b) => a -> b
fromIntegral -> Int
n) =
if Int
n forall a. Ord a => a -> a -> Bool
<= Int
9
then Int -> TextBuilder
unicodeCodePoint (Int
n forall a. Num a => a -> a -> a
+ Int
48)
else Int -> TextBuilder
unicodeCodePoint (Int
n forall a. Num a => a -> a -> a
+ Int
87)
{-# INLINE intercalate #-}
intercalate :: (Foldable f) => TextBuilder -> f TextBuilder -> TextBuilder
intercalate :: forall (f :: * -> *).
Foldable f =>
TextBuilder -> f TextBuilder -> TextBuilder
intercalate TextBuilder
separator = forall {a} {b}. Product2 a b -> b
extract forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' Product2 Bool TextBuilder
-> TextBuilder -> Product2 Bool TextBuilder
step forall {b}. Monoid b => Product2 Bool b
init
where
init :: Product2 Bool b
init = forall a b. a -> b -> Product2 a b
Product2 Bool
False forall a. Monoid a => a
mempty
step :: Product2 Bool TextBuilder
-> TextBuilder -> Product2 Bool TextBuilder
step (Product2 Bool
isNotFirst TextBuilder
builder) TextBuilder
element =
forall a b. a -> b -> Product2 a b
Product2 Bool
True
forall a b. (a -> b) -> a -> b
$ if Bool
isNotFirst
then TextBuilder
builder forall a. Semigroup a => a -> a -> a
<> TextBuilder
separator forall a. Semigroup a => a -> a -> a
<> TextBuilder
element
else TextBuilder
element
extract :: Product2 a b -> b
extract (Product2 a
_ b
builder) = b
builder
{-# INLINE intercalateMap #-}
intercalateMap :: (Foldable f) => TextBuilder -> (a -> TextBuilder) -> f a -> TextBuilder
intercalateMap :: forall (f :: * -> *) a.
Foldable f =>
TextBuilder -> (a -> TextBuilder) -> f a -> TextBuilder
intercalateMap TextBuilder
separator a -> TextBuilder
mapper = forall {a}. Monoid a => Maybe a -> a
extract forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' Maybe TextBuilder -> a -> Maybe TextBuilder
step forall {a}. Maybe a
init
where
init :: Maybe a
init = forall {a}. Maybe a
Nothing
step :: Maybe TextBuilder -> a -> Maybe TextBuilder
step Maybe TextBuilder
acc a
element =
forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ case Maybe TextBuilder
acc of
Maybe TextBuilder
Nothing -> a -> TextBuilder
mapper a
element
Just TextBuilder
acc -> TextBuilder
acc forall a. Semigroup a => a -> a -> a
<> TextBuilder
separator forall a. Semigroup a => a -> a -> a
<> a -> TextBuilder
mapper a
element
extract :: Maybe a -> a
extract = forall a. a -> Maybe a -> a
fromMaybe forall a. Monoid a => a
mempty
{-# INLINEABLE padFromLeft #-}
padFromLeft :: Int -> Char -> TextBuilder -> TextBuilder
padFromLeft :: Int -> Char -> TextBuilder -> TextBuilder
padFromLeft Int
paddedLength Char
paddingChar TextBuilder
builder =
let builderLength :: Int
builderLength = TextBuilder -> Int
length TextBuilder
builder
in if Int
paddedLength forall a. Ord a => a -> a -> Bool
<= Int
builderLength
then TextBuilder
builder
else forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap Char -> TextBuilder
char (forall a. Int -> a -> [a]
replicate (Int
paddedLength forall a. Num a => a -> a -> a
- Int
builderLength) Char
paddingChar) forall a. Semigroup a => a -> a -> a
<> TextBuilder
builder
{-# INLINEABLE padFromRight #-}
padFromRight :: Int -> Char -> TextBuilder -> TextBuilder
padFromRight :: Int -> Char -> TextBuilder -> TextBuilder
padFromRight Int
paddedLength Char
paddingChar TextBuilder
builder =
let builderLength :: Int
builderLength = TextBuilder -> Int
length TextBuilder
builder
in if Int
paddedLength forall a. Ord a => a -> a -> Bool
<= Int
builderLength
then TextBuilder
builder
else TextBuilder
builder forall a. Semigroup a => a -> a -> a
<> forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap Char -> TextBuilder
char (forall a. Int -> a -> [a]
replicate (Int
paddedLength forall a. Num a => a -> a -> a
- Int
builderLength) Char
paddingChar)
utcTimeInIso8601 :: UTCTime -> TextBuilder
utcTimeInIso8601 :: UTCTime -> TextBuilder
utcTimeInIso8601 UTCTime {DiffTime
Day
utctDay :: UTCTime -> Day
utctDayTime :: UTCTime -> DiffTime
utctDayTime :: DiffTime
utctDay :: Day
..} =
let (Year
year, Int
month, Int
day) = Day -> (Year, Int, Int)
toGregorian Day
utctDay
daySeconds :: Int
daySeconds = forall a b. (RealFrac a, Integral b) => a -> b
round DiffTime
utctDayTime
(Int
dayMinutes, Int
second) = forall a. Integral a => a -> a -> (a, a)
divMod Int
daySeconds Int
60
(Int
hour, Int
minute) = forall a. Integral a => a -> a -> (a, a)
divMod Int
dayMinutes Int
60
in Int -> Int -> Int -> Int -> Int -> Int -> TextBuilder
utcTimestampInIso8601 (forall a b. (Integral a, Num b) => a -> b
fromIntegral Year
year) Int
month Int
day Int
hour Int
minute Int
second
utcTimestampInIso8601 ::
Int ->
Int ->
Int ->
Int ->
Int ->
Int ->
TextBuilder
utcTimestampInIso8601 :: Int -> Int -> Int -> Int -> Int -> Int -> TextBuilder
utcTimestampInIso8601 Int
y Int
mo Int
d Int
h Int
mi Int
s =
forall a. Monoid a => [a] -> a
mconcat
[ forall a. Integral a => Int -> a -> TextBuilder
fixedUnsignedDecimal Int
4 Int
y,
TextBuilder
"-",
forall a. Integral a => Int -> a -> TextBuilder
fixedUnsignedDecimal Int
2 Int
mo,
TextBuilder
"-",
forall a. Integral a => Int -> a -> TextBuilder
fixedUnsignedDecimal Int
2 Int
d,
TextBuilder
"T",
forall a. Integral a => Int -> a -> TextBuilder
fixedUnsignedDecimal Int
2 Int
h,
TextBuilder
":",
forall a. Integral a => Int -> a -> TextBuilder
fixedUnsignedDecimal Int
2 Int
mi,
TextBuilder
":",
forall a. Integral a => Int -> a -> TextBuilder
fixedUnsignedDecimal Int
2 Int
s,
TextBuilder
"Z"
]
{-# INLINEABLE intervalInSeconds #-}
intervalInSeconds :: (RealFrac seconds) => seconds -> TextBuilder
intervalInSeconds :: forall seconds. RealFrac seconds => seconds -> TextBuilder
intervalInSeconds seconds
interval = forall a b c. (a -> b -> c) -> b -> a -> c
flip forall s a. State s a -> s -> a
evalState (forall a b. (RealFrac a, Integral b) => a -> b
round seconds
interval) forall a b. (a -> b) -> a -> b
$ do
Year
seconds <- forall (m :: * -> *) s a. Monad m => (s -> (a, s)) -> StateT s m a
state (forall a b. (a, b) -> (b, a)
swap forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a b c. (a -> b -> c) -> b -> a -> c
flip forall a. Integral a => a -> a -> (a, a)
divMod Year
60)
Year
minutes <- forall (m :: * -> *) s a. Monad m => (s -> (a, s)) -> StateT s m a
state (forall a b. (a, b) -> (b, a)
swap forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a b c. (a -> b -> c) -> b -> a -> c
flip forall a. Integral a => a -> a -> (a, a)
divMod Year
60)
Year
hours <- forall (m :: * -> *) s a. Monad m => (s -> (a, s)) -> StateT s m a
state (forall a b. (a, b) -> (b, a)
swap forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a b c. (a -> b -> c) -> b -> a -> c
flip forall a. Integral a => a -> a -> (a, a)
divMod Year
24)
Year
days <- forall (m :: * -> *) s. Monad m => StateT s m s
get
forall (m :: * -> *) a. Monad m => a -> m a
return
forall a b. (a -> b) -> a -> b
$ Int -> Char -> TextBuilder -> TextBuilder
padFromLeft Int
2 Char
'0' (forall a. Integral a => a -> TextBuilder
decimal Year
days)
forall a. Semigroup a => a -> a -> a
<> TextBuilder
":"
forall a. Semigroup a => a -> a -> a
<> Int -> Char -> TextBuilder -> TextBuilder
padFromLeft Int
2 Char
'0' (forall a. Integral a => a -> TextBuilder
decimal Year
hours)
forall a. Semigroup a => a -> a -> a
<> TextBuilder
":"
forall a. Semigroup a => a -> a -> a
<> Int -> Char -> TextBuilder -> TextBuilder
padFromLeft Int
2 Char
'0' (forall a. Integral a => a -> TextBuilder
decimal Year
minutes)
forall a. Semigroup a => a -> a -> a
<> TextBuilder
":"
forall a. Semigroup a => a -> a -> a
<> Int -> Char -> TextBuilder -> TextBuilder
padFromLeft Int
2 Char
'0' (forall a. Integral a => a -> TextBuilder
decimal Year
seconds)
{-# INLINE fixedDouble #-}
fixedDouble ::
Int ->
Double ->
TextBuilder
fixedDouble :: Int -> Double -> TextBuilder
fixedDouble Int
decimalPlaces = forall a. IsString a => String -> a
fromString forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall r. PrintfType r => String -> r
printf (String
"%." forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> String
show Int
decimalPlaces forall a. [a] -> [a] -> [a]
++ String
"f")
{-# INLINE doublePercent #-}
doublePercent ::
Int ->
Double ->
TextBuilder
doublePercent :: Int -> Double -> TextBuilder
doublePercent Int
decimalPlaces Double
x = Int -> Double -> TextBuilder
fixedDouble Int
decimalPlaces (Double
x forall a. Num a => a -> a -> a
* Double
100) forall a. Semigroup a => a -> a -> a
<> TextBuilder
"%"
{-# INLINE hexData #-}
hexData :: ByteString -> TextBuilder
hexData :: ByteString -> TextBuilder
hexData =
forall (f :: * -> *).
Foldable f =>
TextBuilder -> f TextBuilder -> TextBuilder
intercalate TextBuilder
" "
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Monoid a => [a] -> a
mconcat
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall e. Int -> [e] -> [[e]]
Split.chunksOf Int
2
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Integral a => a -> TextBuilder
byte
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. ByteString -> [Word8]
ByteString.unpack
where
byte :: a -> TextBuilder
byte =
Int -> Char -> TextBuilder -> TextBuilder
padFromLeft Int
2 Char
'0' forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a. Integral a => a -> TextBuilder
unsignedHexadecimal