{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE LambdaCase #-}
module Formatting.Combinators
(
maybed
, optioned
, eithered
, lefted
, righted
, concatenated
, joinedWith
, intercalated
, unworded
, unlined
, spaced
, commaSep
, commaSpaceSep
, list
, qlist
, took
, dropped
, splat
, splatWith
, splatOn
, worded
, lined
, alteredWith
, charsKeptIf
, charsRemovedIf
, replaced
, uppercased
, lowercased
, titlecased
, ltruncated
, ctruncated
, rtruncated
, lpadded
, rpadded
, cpadded
, lfixed
, rfixed
, cfixed
, prefixed
, suffixed
, surrounded
, enclosed
, squoted
, dquoted
, parenthesised
, squared
, braced
, angled
, backticked
, indented
, indentedLines
, reindented
, roundedTo
, truncatedTo
, ceilingedTo
, flooredTo
, viewed
, accessed
, binPrefix
, octPrefix
, hexPrefix
) where
import Control.Applicative (Const(..), getConst)
import Control.Category ((>>>))
import Data.Foldable (toList)
import Data.Function ((&))
import Data.Int (Int64)
import Data.Text.Lazy (Text)
import qualified Data.Text.Lazy as TL
import Data.Text.Lazy.Builder (Builder)
import qualified Data.Text.Lazy.Builder as TLB
import Formatting.Internal
import Formatting.Formatters
maybed
:: Builder
-> Format Builder (a -> Builder)
-> Format r (Maybe a -> r)
maybed :: Builder -> Format Builder (a -> Builder) -> Format r (Maybe a -> r)
maybed Builder
whenNothing Format Builder (a -> Builder)
f = (Maybe a -> Builder) -> Format r (Maybe a -> r)
forall a r. (a -> Builder) -> Format r (a -> r)
later ((Maybe a -> Builder) -> Format r (Maybe a -> r))
-> (Maybe a -> Builder) -> Format r (Maybe a -> r)
forall a b. (a -> b) -> a -> b
$ \case
Maybe a
Nothing -> Builder
whenNothing
Just a
x -> Format Builder (a -> Builder) -> a -> Builder
forall a. Format Builder a -> a
bformat Format Builder (a -> Builder)
f a
x
{-# INLINE maybed #-}
optioned :: Format Builder (a -> Builder) -> Format r (Maybe a -> r)
optioned :: Format Builder (a -> Builder) -> Format r (Maybe a -> r)
optioned = Builder -> Format Builder (a -> Builder) -> Format r (Maybe a -> r)
forall a r.
Builder -> Format Builder (a -> Builder) -> Format r (Maybe a -> r)
maybed Builder
""
{-# INLINE optioned #-}
eithered
:: Format Builder (a -> Builder)
-> Format Builder (b -> Builder)
-> Format r (Either a b -> r)
eithered :: Format Builder (a -> Builder)
-> Format Builder (b -> Builder) -> Format r (Either a b -> r)
eithered Format Builder (a -> Builder)
l Format Builder (b -> Builder)
r = (Either a b -> Builder) -> Format r (Either a b -> r)
forall a r. (a -> Builder) -> Format r (a -> r)
later ((Either a b -> Builder) -> Format r (Either a b -> r))
-> (Either a b -> Builder) -> Format r (Either a b -> r)
forall a b. (a -> b) -> a -> b
$ \case
Left a
x -> Format Builder (a -> Builder) -> a -> Builder
forall a. Format Builder a -> a
bformat Format Builder (a -> Builder)
l a
x
Right b
x -> Format Builder (b -> Builder) -> b -> Builder
forall a. Format Builder a -> a
bformat Format Builder (b -> Builder)
r b
x
{-# INLINE eithered #-}
lefted :: Format Builder (a -> Builder) -> Format r (Either a x -> r)
lefted :: Format Builder (a -> Builder) -> Format r (Either a x -> r)
lefted Format Builder (a -> Builder)
f = Format Builder (a -> Builder)
-> Format Builder (x -> Builder) -> Format r (Either a x -> r)
forall a b r.
Format Builder (a -> Builder)
-> Format Builder (b -> Builder) -> Format r (Either a b -> r)
eithered Format Builder (a -> Builder)
f (Builder -> Format Builder (x -> Builder)
forall r a. Builder -> Format r (a -> r)
fconst Builder
"")
{-# INLINE lefted #-}
righted :: Format Builder (a -> Builder) -> Format r (Either x a -> r)
righted :: Format Builder (a -> Builder) -> Format r (Either x a -> r)
righted = Format Builder (x -> Builder)
-> Format Builder (a -> Builder) -> Format r (Either x a -> r)
forall a b r.
Format Builder (a -> Builder)
-> Format Builder (b -> Builder) -> Format r (Either a b -> r)
eithered (Builder -> Format Builder (x -> Builder)
forall r a. Builder -> Format r (a -> r)
fconst Builder
"")
{-# INLINE righted #-}
concatenated :: Foldable t => Format Builder (a -> Builder) -> Format r (t a -> r)
concatenated :: Format Builder (a -> Builder) -> Format r (t a -> r)
concatenated Format Builder (a -> Builder)
f = (t a -> Builder) -> Format r (t a -> r)
forall a r. (a -> Builder) -> Format r (a -> r)
later ((t a -> Builder) -> Format r (t a -> r))
-> (t a -> Builder) -> Format r (t a -> r)
forall a b. (a -> b) -> a -> b
$ (a -> Builder) -> t a -> Builder
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (Format Builder (a -> Builder) -> a -> Builder
forall a. Format Builder a -> a
bformat Format Builder (a -> Builder)
f)
{-# INLINE concatenated #-}
joinedWith :: Foldable t => ([Text] -> Text) -> Format Builder (a -> Builder) -> Format r (t a -> r)
joinedWith :: ([Text] -> Text)
-> Format Builder (a -> Builder) -> Format r (t a -> r)
joinedWith [Text] -> Text
joiner Format Builder (a -> Builder)
f = (t a -> Builder) -> Format r (t a -> r)
forall a r. (a -> Builder) -> Format r (a -> r)
later ((t a -> Builder) -> Format r (t a -> r))
-> (t a -> Builder) -> Format r (t a -> r)
forall a b. (a -> b) -> a -> b
$ t a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList
(t a -> [a]) -> ([a] -> Builder) -> t a -> Builder
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> (a -> Text) -> [a] -> [Text]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Format Builder (a -> Builder) -> a -> Builder
forall a. Format Builder a -> a
bformat Format Builder (a -> Builder)
f (a -> Builder) -> (Builder -> Text) -> a -> Text
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> Builder -> Text
TLB.toLazyText)
([a] -> [Text]) -> ([Text] -> Builder) -> [a] -> Builder
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> [Text] -> Text
joiner
([Text] -> Text) -> (Text -> Builder) -> [Text] -> Builder
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> Text -> Builder
TLB.fromLazyText
{-# INLINABLE joinedWith #-}
intercalated :: Foldable t => Text -> Format Builder (a -> Builder) -> Format r (t a -> r)
intercalated :: Text -> Format Builder (a -> Builder) -> Format r (t a -> r)
intercalated Text
s = ([Text] -> Text)
-> Format Builder (a -> Builder) -> Format r (t a -> r)
forall (t :: * -> *) a r.
Foldable t =>
([Text] -> Text)
-> Format Builder (a -> Builder) -> Format r (t a -> r)
joinedWith (Text -> [Text] -> Text
TL.intercalate Text
s)
{-# INLINE intercalated #-}
unworded :: Foldable t => Format Builder (a -> Builder) -> Format r (t a -> r)
unworded :: Format Builder (a -> Builder) -> Format r (t a -> r)
unworded = ([Text] -> Text)
-> Format Builder (a -> Builder) -> Format r (t a -> r)
forall (t :: * -> *) a r.
Foldable t =>
([Text] -> Text)
-> Format Builder (a -> Builder) -> Format r (t a -> r)
joinedWith [Text] -> Text
TL.unwords
{-# INLINE unworded #-}
unlined :: Foldable t => Format Builder (a -> Builder) -> Format r (t a -> r)
unlined :: Format Builder (a -> Builder) -> Format r (t a -> r)
unlined = ([Text] -> Text)
-> Format Builder (a -> Builder) -> Format r (t a -> r)
forall (t :: * -> *) a r.
Foldable t =>
([Text] -> Text)
-> Format Builder (a -> Builder) -> Format r (t a -> r)
joinedWith [Text] -> Text
TL.unlines
{-# INLINE unlined #-}
spaced :: Foldable t => Format Builder (a -> Builder) -> Format r (t a -> r)
spaced :: Format Builder (a -> Builder) -> Format r (t a -> r)
spaced = Text -> Format Builder (a -> Builder) -> Format r (t a -> r)
forall (t :: * -> *) a r.
Foldable t =>
Text -> Format Builder (a -> Builder) -> Format r (t a -> r)
intercalated Text
" "
{-# INLINE spaced #-}
commaSep :: Foldable t => Format Builder (a -> Builder) -> Format r (t a -> r)
commaSep :: Format Builder (a -> Builder) -> Format r (t a -> r)
commaSep = Text -> Format Builder (a -> Builder) -> Format r (t a -> r)
forall (t :: * -> *) a r.
Foldable t =>
Text -> Format Builder (a -> Builder) -> Format r (t a -> r)
intercalated Text
","
{-# INLINE commaSep #-}
commaSpaceSep :: Foldable t => Format Builder (a -> Builder) -> Format r (t a -> r)
commaSpaceSep :: Format Builder (a -> Builder) -> Format r (t a -> r)
commaSpaceSep = Text -> Format Builder (a -> Builder) -> Format r (t a -> r)
forall (t :: * -> *) a r.
Foldable t =>
Text -> Format Builder (a -> Builder) -> Format r (t a -> r)
intercalated Text
", "
{-# INLINE commaSpaceSep #-}
list :: Foldable t => Format Builder (a -> Builder) -> Format r (t a -> r)
list :: Format Builder (a -> Builder) -> Format r (t a -> r)
list = Format Builder (a -> Builder) -> Format r (t a -> r)
forall (t :: * -> *) a r.
Foldable t =>
Format Builder (a -> Builder) -> Format r (t a -> r)
commaSpaceSep (Format Builder (a -> Builder) -> Format r (t a -> r))
-> (Format r (t a -> r) -> Format r (t a -> r))
-> Format Builder (a -> Builder)
-> Format r (t a -> r)
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> Format r (t a -> r) -> Format r (t a -> r)
forall r a. Format r a -> Format r a
squared
{-# INLINE list #-}
qlist :: Foldable t => Format Builder (a -> Builder) -> Format r (t a -> r)
qlist :: Format Builder (a -> Builder) -> Format r (t a -> r)
qlist = Format Builder (a -> Builder) -> Format Builder (a -> Builder)
forall r a. Format r a -> Format r a
dquoted (Format Builder (a -> Builder) -> Format Builder (a -> Builder))
-> (Format Builder (a -> Builder) -> Format r (t a -> r))
-> Format Builder (a -> Builder)
-> Format r (t a -> r)
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> Format Builder (a -> Builder) -> Format r (t a -> r)
forall (t :: * -> *) a r.
Foldable t =>
Format Builder (a -> Builder) -> Format r (t a -> r)
commaSpaceSep (Format Builder (a -> Builder) -> Format r (t a -> r))
-> (Format r (t a -> r) -> Format r (t a -> r))
-> Format Builder (a -> Builder)
-> Format r (t a -> r)
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> Format r (t a -> r) -> Format r (t a -> r)
forall r a. Format r a -> Format r a
squared
{-# INLINE qlist #-}
took :: Int -> Format r ([a] -> r) -> Format r ([a] -> r)
took :: Int -> Format r ([a] -> r) -> Format r ([a] -> r)
took Int
n = (([a] -> r) -> [a] -> r)
-> Format r ([a] -> r) -> Format r ([a] -> r)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (([a] -> r) -> ([a] -> [a]) -> [a] -> r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> [a] -> [a]
forall a. Int -> [a] -> [a]
take Int
n)
{-# INLINE took #-}
dropped :: Int -> Format r ([a] -> r) -> Format r ([a] -> r)
dropped :: Int -> Format r ([a] -> r) -> Format r ([a] -> r)
dropped Int
n = (([a] -> r) -> [a] -> r)
-> Format r ([a] -> r) -> Format r ([a] -> r)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (([a] -> r) -> ([a] -> [a]) -> [a] -> r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> [a] -> [a]
forall a. Int -> [a] -> [a]
drop Int
n)
{-# INLINE dropped #-}
splatWith
:: (Text -> [Text])
-> (Format r' (Builder -> r') -> Format Builder ([Builder] -> Builder))
-> Format r a
-> Format r a
splatWith :: (Text -> [Text])
-> (Format r' (Builder -> r')
-> Format Builder ([Builder] -> Builder))
-> Format r a
-> Format r a
splatWith Text -> [Text]
splitter Format r' (Builder -> r') -> Format Builder ([Builder] -> Builder)
lf Format r a
f = (Builder -> Builder) -> Format r (Builder -> r)
forall a r. (a -> Builder) -> Format r (a -> r)
later (Builder -> Text
TLB.toLazyText
(Builder -> Text) -> (Text -> Builder) -> Builder -> Builder
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> Text -> [Text]
splitter
(Text -> [Text]) -> ([Text] -> Builder) -> Text -> Builder
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> (Text -> Builder) -> [Text] -> [Builder]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Text -> Builder
TLB.fromLazyText
([Text] -> [Builder])
-> ([Builder] -> Builder) -> [Text] -> Builder
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> Format Builder ([Builder] -> Builder) -> [Builder] -> Builder
forall a. Format Builder a -> a
bformat (Format r' (Builder -> r') -> Format Builder ([Builder] -> Builder)
lf Format r' (Builder -> r')
forall r. Format r (Builder -> r)
builder))
Format r (Builder -> r) -> Format r a -> Format r a
forall r r' a.
Format r (Builder -> r') -> Format r' a -> Format r a
%. Format r a
f
{-# INLINABLE splatWith #-}
splat
:: (Char -> Bool)
-> (Format r' (Builder -> r') -> Format Builder ([Builder] -> Builder))
-> Format r a
-> Format r a
splat :: (Char -> Bool)
-> (Format r' (Builder -> r')
-> Format Builder ([Builder] -> Builder))
-> Format r a
-> Format r a
splat Char -> Bool
p = (Text -> [Text])
-> (Format r' (Builder -> r')
-> Format Builder ([Builder] -> Builder))
-> Format r a
-> Format r a
forall r' r a.
(Text -> [Text])
-> (Format r' (Builder -> r')
-> Format Builder ([Builder] -> Builder))
-> Format r a
-> Format r a
splatWith ((Char -> Bool) -> Text -> [Text]
TL.split Char -> Bool
p)
{-# INLINE splat #-}
splatOn
:: Text
-> (Format r' (Builder -> r') -> Format Builder ([Builder] -> Builder))
-> Format r a
-> Format r a
splatOn :: Text
-> (Format r' (Builder -> r')
-> Format Builder ([Builder] -> Builder))
-> Format r a
-> Format r a
splatOn Text
t = (Text -> [Text])
-> (Format r' (Builder -> r')
-> Format Builder ([Builder] -> Builder))
-> Format r a
-> Format r a
forall r' r a.
(Text -> [Text])
-> (Format r' (Builder -> r')
-> Format Builder ([Builder] -> Builder))
-> Format r a
-> Format r a
splatWith (Text -> Text -> [Text]
TL.splitOn Text
t)
{-# INLINE splatOn #-}
worded
:: (Format r' (Builder -> r') -> Format Builder ([Builder] -> Builder))
-> Format r a
-> Format r a
worded :: (Format r' (Builder -> r')
-> Format Builder ([Builder] -> Builder))
-> Format r a -> Format r a
worded = (Text -> [Text])
-> (Format r' (Builder -> r')
-> Format Builder ([Builder] -> Builder))
-> Format r a
-> Format r a
forall r' r a.
(Text -> [Text])
-> (Format r' (Builder -> r')
-> Format Builder ([Builder] -> Builder))
-> Format r a
-> Format r a
splatWith Text -> [Text]
TL.words
{-# INLINE worded #-}
lined
:: (Format Builder (Builder -> Builder) -> Format Builder ([Builder] -> Builder))
-> Format r a
-> Format r a
lined :: (Format Builder (Builder -> Builder)
-> Format Builder ([Builder] -> Builder))
-> Format r a -> Format r a
lined = (Text -> [Text])
-> (Format Builder (Builder -> Builder)
-> Format Builder ([Builder] -> Builder))
-> Format r a
-> Format r a
forall r' r a.
(Text -> [Text])
-> (Format r' (Builder -> r')
-> Format Builder ([Builder] -> Builder))
-> Format r a
-> Format r a
splatWith Text -> [Text]
TL.lines
{-# INLINE lined #-}
alteredWith :: (Text -> Text) -> Format r a -> Format r a
alteredWith :: (Text -> Text) -> Format r a -> Format r a
alteredWith Text -> Text
alterer Format r a
f =
(Builder -> Builder) -> Format r (Builder -> r)
forall a r. (a -> Builder) -> Format r (a -> r)
later (Builder -> Text
TLB.toLazyText (Builder -> Text) -> (Text -> Builder) -> Builder -> Builder
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> Text -> Text
alterer (Text -> Text) -> (Text -> Builder) -> Text -> Builder
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> Text -> Builder
TLB.fromLazyText) Format r (Builder -> r) -> Format r a -> Format r a
forall r r' a.
Format r (Builder -> r') -> Format r' a -> Format r a
%. Format r a
f
{-# INLINABLE alteredWith #-}
charsKeptIf :: (Char -> Bool) -> Format r a -> Format r a
charsKeptIf :: (Char -> Bool) -> Format r a -> Format r a
charsKeptIf Char -> Bool
p = (Text -> Text) -> Format r a -> Format r a
forall r a. (Text -> Text) -> Format r a -> Format r a
alteredWith ((Char -> Bool) -> Text -> Text
TL.filter Char -> Bool
p)
{-# INLINE charsKeptIf #-}
charsRemovedIf :: (Char -> Bool) -> Format r a -> Format r a
charsRemovedIf :: (Char -> Bool) -> Format r a -> Format r a
charsRemovedIf Char -> Bool
p = (Text -> Text) -> Format r a -> Format r a
forall r a. (Text -> Text) -> Format r a -> Format r a
alteredWith ((Char -> Bool) -> Text -> Text
TL.filter (Bool -> Bool
not (Bool -> Bool) -> (Char -> Bool) -> Char -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Bool
p))
{-# INLINE charsRemovedIf #-}
replaced :: Text -> Text -> Format r a -> Format r a
replaced :: Text -> Text -> Format r a -> Format r a
replaced Text
needle Text
replacement = (Text -> Text) -> Format r a -> Format r a
forall r a. (Text -> Text) -> Format r a -> Format r a
alteredWith (Text -> Text -> Text -> Text
TL.replace Text
needle Text
replacement)
{-# INLINE replaced #-}
uppercased :: Format r a -> Format r a
uppercased :: Format r a -> Format r a
uppercased = (Text -> Text) -> Format r a -> Format r a
forall r a. (Text -> Text) -> Format r a -> Format r a
alteredWith Text -> Text
TL.toUpper
{-# INLINE uppercased #-}
lowercased :: Format r a -> Format r a
lowercased :: Format r a -> Format r a
lowercased = (Text -> Text) -> Format r a -> Format r a
forall r a. (Text -> Text) -> Format r a -> Format r a
alteredWith Text -> Text
TL.toLower
{-# INLINE lowercased #-}
titlecased :: Format r a -> Format r a
titlecased :: Format r a -> Format r a
titlecased = (Text -> Text) -> Format r a -> Format r a
forall r a. (Text -> Text) -> Format r a -> Format r a
alteredWith Text -> Text
TL.toTitle
{-# INLINE titlecased #-}
ltruncated :: Int64 -> Format r a -> Format r a
ltruncated :: Int64 -> Format r a -> Format r a
ltruncated Int64
n = Int64 -> Int64 -> Format r a -> Format r a
forall r a. Int64 -> Int64 -> Format r a -> Format r a
ctruncated (Int64
n Int64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
- Int64
3) Int64
0
{-# INLINE ltruncated #-}
rtruncated :: Int64 -> Format r a -> Format r a
rtruncated :: Int64 -> Format r a -> Format r a
rtruncated Int64
n = Int64 -> Int64 -> Format r a -> Format r a
forall r a. Int64 -> Int64 -> Format r a -> Format r a
ctruncated Int64
0 (Int64
n Int64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
- Int64
3)
{-# INLINE rtruncated #-}
ctruncated :: Int64 -> Int64 -> Format r a -> Format r a
ctruncated :: Int64 -> Int64 -> Format r a -> Format r a
ctruncated Int64
start Int64
end = (Text -> Text) -> Format r a -> Format r a
forall r a. (Text -> Text) -> Format r a -> Format r a
alteredWith Text -> Text
shorten
where
shorten :: Text -> Text
shorten :: Text -> Text
shorten Text
txt =
let n :: Int64
n = Int64
start Int64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
+ Int64
end Int64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
+ Int64
3
in if Text -> Int64
TL.length Text
txt Int64 -> Int64 -> Bool
forall a. Ord a => a -> a -> Bool
<= Int64
n
then Text
txt
else Int64 -> Text -> Text
TL.take Int64
start Text
txt Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"..." Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Int64 -> Text -> Text
TL.takeEnd Int64
end Text
txt
{-# INLINABLE ctruncated #-}
lpadded :: Int64 -> Char -> Format r (a -> r) -> Format r (a -> r)
lpadded :: Int64 -> Char -> Format r (a -> r) -> Format r (a -> r)
lpadded Int64
i Char
c = (Text -> Text) -> Format r (a -> r) -> Format r (a -> r)
forall r a. (Text -> Text) -> Format r a -> Format r a
alteredWith (Int64 -> Char -> Text -> Text
TL.justifyRight Int64
i Char
c)
{-# INLINE lpadded #-}
rpadded :: Int64 -> Char -> Format r (a -> r) -> Format r (a -> r)
rpadded :: Int64 -> Char -> Format r (a -> r) -> Format r (a -> r)
rpadded Int64
i Char
c = (Text -> Text) -> Format r (a -> r) -> Format r (a -> r)
forall r a. (Text -> Text) -> Format r a -> Format r a
alteredWith (Int64 -> Char -> Text -> Text
TL.justifyLeft Int64
i Char
c)
{-# INLINE rpadded #-}
cpadded :: Int64 -> Char -> Format r (a -> r) -> Format r (a -> r)
cpadded :: Int64 -> Char -> Format r (a -> r) -> Format r (a -> r)
cpadded Int64
i Char
c = (Text -> Text) -> Format r (a -> r) -> Format r (a -> r)
forall r a. (Text -> Text) -> Format r a -> Format r a
alteredWith (Int64 -> Char -> Text -> Text
TL.center Int64
i Char
c)
{-# INLINE cpadded #-}
lfixed :: Int64 -> Char -> Format r (a -> r) -> Format r (a -> r)
lfixed :: Int64 -> Char -> Format r (a -> r) -> Format r (a -> r)
lfixed Int64
n Char
c = Int64 -> Format r (a -> r) -> Format r (a -> r)
forall r a. Int64 -> Format r a -> Format r a
ltruncated Int64
n (Format r (a -> r) -> Format r (a -> r))
-> (Format r (a -> r) -> Format r (a -> r))
-> Format r (a -> r)
-> Format r (a -> r)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int64 -> Char -> Format r (a -> r) -> Format r (a -> r)
forall r a. Int64 -> Char -> Format r (a -> r) -> Format r (a -> r)
rpadded Int64
n Char
c
{-# INLINE lfixed #-}
rfixed :: Int64 -> Char -> Format r (a -> r) -> Format r (a -> r)
rfixed :: Int64 -> Char -> Format r (a -> r) -> Format r (a -> r)
rfixed Int64
n Char
c = Int64 -> Format r (a -> r) -> Format r (a -> r)
forall r a. Int64 -> Format r a -> Format r a
rtruncated Int64
n (Format r (a -> r) -> Format r (a -> r))
-> (Format r (a -> r) -> Format r (a -> r))
-> Format r (a -> r)
-> Format r (a -> r)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int64 -> Char -> Format r (a -> r) -> Format r (a -> r)
forall r a. Int64 -> Char -> Format r (a -> r) -> Format r (a -> r)
lpadded Int64
n Char
c
{-# INLINE rfixed #-}
cfixed :: Int64 -> Int64 -> Char -> Format r (a -> r) -> Format r (a -> r)
cfixed :: Int64 -> Int64 -> Char -> Format r (a -> r) -> Format r (a -> r)
cfixed Int64
l Int64
r Char
c = Int64 -> Int64 -> Format r (a -> r) -> Format r (a -> r)
forall r a. Int64 -> Int64 -> Format r a -> Format r a
ctruncated Int64
l Int64
r (Format r (a -> r) -> Format r (a -> r))
-> (Format r (a -> r) -> Format r (a -> r))
-> Format r (a -> r)
-> Format r (a -> r)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int64 -> Char -> Format r (a -> r) -> Format r (a -> r)
forall r a. Int64 -> Char -> Format r (a -> r) -> Format r (a -> r)
cpadded (Int64
l Int64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
+ Int64
r Int64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
+ Int64
3) Char
c
{-# INLINE cfixed #-}
prefixed :: Builder -> Format r a -> Format r a
prefixed :: Builder -> Format r a -> Format r a
prefixed Builder
s Format r a
f = Builder -> Format a a
forall r. Builder -> Format r r
now Builder
s Format a a -> Format r a -> Format r a
forall r a r'. Format r a -> Format r' r -> Format r' a
% Format r a
f
{-# INLINE prefixed #-}
suffixed :: Builder -> Format r a -> Format r a
suffixed :: Builder -> Format r a -> Format r a
suffixed Builder
s Format r a
f = Format r a
f Format r a -> Format r r -> Format r a
forall r a r'. Format r a -> Format r' r -> Format r' a
% Builder -> Format r r
forall r. Builder -> Format r r
now Builder
s
{-# INLINE suffixed #-}
surrounded :: Builder -> Format r a -> Format r a
surrounded :: Builder -> Format r a -> Format r a
surrounded Builder
s Format r a
f = Builder -> Format a a
forall r. Builder -> Format r r
now Builder
s Format a a -> Format r a -> Format r a
forall r a r'. Format r a -> Format r' r -> Format r' a
% Format r a
f Format r a -> Format r r -> Format r a
forall r a r'. Format r a -> Format r' r -> Format r' a
% Builder -> Format r r
forall r. Builder -> Format r r
now Builder
s
{-# INLINE surrounded #-}
enclosed :: Builder -> Builder -> Format r a -> Format r a
enclosed :: Builder -> Builder -> Format r a -> Format r a
enclosed Builder
pre Builder
suf Format r a
f = Builder -> Format a a
forall r. Builder -> Format r r
now Builder
pre Format a a -> Format r a -> Format r a
forall r a r'. Format r a -> Format r' r -> Format r' a
% Format r a
f Format r a -> Format r r -> Format r a
forall r a r'. Format r a -> Format r' r -> Format r' a
% Builder -> Format r r
forall r. Builder -> Format r r
now Builder
suf
{-# INLINE enclosed #-}
squoted :: Format r a -> Format r a
squoted :: Format r a -> Format r a
squoted = Builder -> Format r a -> Format r a
forall r a. Builder -> Format r a -> Format r a
surrounded Builder
"'"
{-# INLINE squoted #-}
dquoted :: Format r a -> Format r a
dquoted :: Format r a -> Format r a
dquoted = Builder -> Format r a -> Format r a
forall r a. Builder -> Format r a -> Format r a
surrounded Builder
"\""
{-# INLINE dquoted #-}
parenthesised :: Format r a -> Format r a
parenthesised :: Format r a -> Format r a
parenthesised = Builder -> Builder -> Format r a -> Format r a
forall r a. Builder -> Builder -> Format r a -> Format r a
enclosed Builder
"(" Builder
")"
{-# INLINE parenthesised #-}
squared :: Format r a -> Format r a
squared :: Format r a -> Format r a
squared = Builder -> Builder -> Format r a -> Format r a
forall r a. Builder -> Builder -> Format r a -> Format r a
enclosed Builder
"[" Builder
"]"
{-# INLINE squared #-}
braced :: Format r a -> Format r a
braced :: Format r a -> Format r a
braced = Builder -> Builder -> Format r a -> Format r a
forall r a. Builder -> Builder -> Format r a -> Format r a
enclosed Builder
"{" Builder
"}"
{-# INLINE braced #-}
angled :: Format r a -> Format r a
angled :: Format r a -> Format r a
angled = Builder -> Builder -> Format r a -> Format r a
forall r a. Builder -> Builder -> Format r a -> Format r a
enclosed Builder
"<" Builder
">"
{-# INLINE angled #-}
backticked :: Format r a -> Format r a
backticked :: Format r a -> Format r a
backticked = Builder -> Format r a -> Format r a
forall r a. Builder -> Format r a -> Format r a
surrounded Builder
"`"
{-# INLINE backticked #-}
indented :: Int -> Format r a -> Format r a
indented :: Int -> Format r a -> Format r a
indented Int
n = Builder -> Format r a -> Format r a
forall r a. Builder -> Format r a -> Format r a
prefixed Builder
spaces
where
spaces :: Builder
spaces = Int64 -> Text -> Text
TL.replicate (Int -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
n) (Char -> Text
TL.singleton Char
' ') Text -> (Text -> Builder) -> Builder
forall a b. a -> (a -> b) -> b
& Text -> Builder
TLB.fromLazyText
{-# INLINABLE indented #-}
indentedLines :: Foldable t => Int -> Format Builder (a -> Builder) -> Format r (t a -> r)
indentedLines :: Int -> Format Builder (a -> Builder) -> Format r (t a -> r)
indentedLines Int
n = Format Builder (a -> Builder) -> Format r (t a -> r)
forall (t :: * -> *) a r.
Foldable t =>
Format Builder (a -> Builder) -> Format r (t a -> r)
unlined (Format Builder (a -> Builder) -> Format r (t a -> r))
-> (Format Builder (a -> Builder) -> Format Builder (a -> Builder))
-> Format Builder (a -> Builder)
-> Format r (t a -> r)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int
-> Format Builder (a -> Builder) -> Format Builder (a -> Builder)
forall r a. Int -> Format r a -> Format r a
indented Int
n
{-# INLINE indentedLines #-}
reindented :: Int -> Format r a -> Format r a
reindented :: Int -> Format r a -> Format r a
reindented Int
n = (Format Builder (Builder -> Builder)
-> Format Builder ([Builder] -> Builder))
-> Format r a -> Format r a
forall r a.
(Format Builder (Builder -> Builder)
-> Format Builder ([Builder] -> Builder))
-> Format r a -> Format r a
lined (Int
-> Format Builder (Builder -> Builder)
-> Format Builder ([Builder] -> Builder)
forall (t :: * -> *) a r.
Foldable t =>
Int -> Format Builder (a -> Builder) -> Format r (t a -> r)
indentedLines Int
n)
{-# INLINE reindented #-}
roundedTo :: (Integral i, RealFrac d, Functor f) => f (i -> r) -> f (d -> r)
roundedTo :: f (i -> r) -> f (d -> r)
roundedTo = ((i -> r) -> d -> r) -> f (i -> r) -> f (d -> r)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((i -> r) -> (d -> i) -> d -> r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. d -> i
forall a b. (RealFrac a, Integral b) => a -> b
round)
{-# INLINE roundedTo #-}
truncatedTo :: (Integral i, RealFrac d, Functor f) => f (i -> r) -> f (d -> r)
truncatedTo :: f (i -> r) -> f (d -> r)
truncatedTo = ((i -> r) -> d -> r) -> f (i -> r) -> f (d -> r)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((i -> r) -> (d -> i) -> d -> r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. d -> i
forall a b. (RealFrac a, Integral b) => a -> b
truncate)
{-# INLINE truncatedTo #-}
ceilingedTo :: (Integral i, RealFrac d, Functor f) => f (i -> r) -> f (d -> r)
ceilingedTo :: f (i -> r) -> f (d -> r)
ceilingedTo = ((i -> r) -> d -> r) -> f (i -> r) -> f (d -> r)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((i -> r) -> (d -> i) -> d -> r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. d -> i
forall a b. (RealFrac a, Integral b) => a -> b
ceiling)
{-# INLINE ceilingedTo #-}
flooredTo :: (Integral i, RealFrac d, Functor f) => f (i -> r) -> f (d -> r)
flooredTo :: f (i -> r) -> f (d -> r)
flooredTo = ((i -> r) -> d -> r) -> f (i -> r) -> f (d -> r)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((i -> r) -> (d -> i) -> d -> r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. d -> i
forall a b. (RealFrac a, Integral b) => a -> b
floor)
{-# INLINE flooredTo #-}
viewed :: ((a -> Const a b) -> s -> Const a t) -> Format r (a -> r) -> Format r (s -> r)
viewed :: ((a -> Const a b) -> s -> Const a t)
-> Format r (a -> r) -> Format r (s -> r)
viewed (a -> Const a b) -> s -> Const a t
l = ((a -> r) -> s -> r) -> Format r (a -> r) -> Format r (s -> r)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((a -> r) -> (s -> a) -> s -> r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Const a t -> a
forall a k (b :: k). Const a b -> a
getConst (Const a t -> a) -> (s -> Const a t) -> s -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Const a b) -> s -> Const a t
l a -> Const a b
forall k a (b :: k). a -> Const a b
Const))
{-# INLINE viewed #-}
accessed :: (s -> a) -> Format r (a -> r) -> Format r (s -> r)
accessed :: (s -> a) -> Format r (a -> r) -> Format r (s -> r)
accessed s -> a
accessor = ((a -> r) -> s -> r) -> Format r (a -> r) -> Format r (s -> r)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((a -> r) -> (s -> a) -> s -> r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. s -> a
accessor)
{-# INLINE accessed #-}
binPrefix :: Integral a => Int64 -> Format r (a -> r)
binPrefix :: Int64 -> Format r (a -> r)
binPrefix Int64
n = Format (a -> r) (a -> r)
"0b" Format (a -> r) (a -> r) -> Format r (a -> r) -> Format r (a -> r)
forall r a r'. Format r a -> Format r' r -> Format r' a
% Int64 -> Char -> Format r (a -> r) -> Format r (a -> r)
forall r a. Int64 -> Char -> Format r (a -> r) -> Format r (a -> r)
lpadded Int64
n Char
'0' Format r (a -> r)
forall a r. Integral a => Format r (a -> r)
bin
{-# INLINE binPrefix #-}
octPrefix :: Integral a => Int64 -> Format r (a -> r)
octPrefix :: Int64 -> Format r (a -> r)
octPrefix Int64
n = Format (a -> r) (a -> r)
"0o" Format (a -> r) (a -> r) -> Format r (a -> r) -> Format r (a -> r)
forall r a r'. Format r a -> Format r' r -> Format r' a
% Int64 -> Char -> Format r (a -> r) -> Format r (a -> r)
forall r a. Int64 -> Char -> Format r (a -> r) -> Format r (a -> r)
lpadded Int64
n Char
'0' Format r (a -> r)
forall a r. Integral a => Format r (a -> r)
oct
{-# INLINE octPrefix #-}
hexPrefix :: Integral a => Int64 -> Format r (a -> r)
hexPrefix :: Int64 -> Format r (a -> r)
hexPrefix Int64
n = Format (a -> r) (a -> r)
"0x" Format (a -> r) (a -> r) -> Format r (a -> r) -> Format r (a -> r)
forall r a r'. Format r a -> Format r' r -> Format r' a
% Int64 -> Char -> Format r (a -> r) -> Format r (a -> r)
forall r a. Int64 -> Char -> Format r (a -> r) -> Format r (a -> r)
lpadded Int64
n Char
'0' Format r (a -> r)
forall a r. Integral a => Format r (a -> r)
hex
{-# INLINE hexPrefix #-}