{-# LANGUAGE OverloadedStrings, RelaxedPolyRec #-}
module Data.Text.Format
(
left
, right
, hex
, fixed
, shortest
) where
import Data.Double.Conversion.Text
import qualified Formatting.Buildable as B
import Data.Text.Format.Types (Hex(..))
import qualified Data.Text.Lazy as LT
import Data.Text.Lazy.Builder
import Prelude hiding (exp, print)
left :: B.Buildable a => Int -> Char -> a -> Builder
left k c =
fromLazyText . LT.justifyRight (fromIntegral k) c . toLazyText . B.build
right :: B.Buildable a => Int -> Char -> a -> Builder
right k c =
fromLazyText . LT.justifyLeft (fromIntegral k) c . toLazyText . B.build
fixed :: (Real a) =>
Int
-> a -> Builder
fixed decs = fromText . toFixed decs . realToFrac
{-# NOINLINE[0] fixed #-}
shortest :: Real a => a -> Builder
shortest = fromText . toShortest . realToFrac
{-# INLINE shortest #-}
hex :: Integral a => a -> Builder
hex = B.build . Hex
{-# INLINE hex #-}