-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A new formatting library -- -- A new formatting library that tries to be simple to understand while -- still being powerful and providing more convenience features than -- other libraries (like functions for pretty-printing maps and lists, or -- a function for printing arbitrary datatypes using generics). -- -- A comparison with other libraries: -- -- @package fmt @version 0.6 module Fmt.Internal.Core class FromBuilder a -- | Convert a Builder to something else. fromBuilder :: FromBuilder a => Builder -> a -- | Concatenate, then convert. (+|) :: (FromBuilder b) => Builder -> Builder -> b infixr 1 +| -- | build and concatenate, then convert. (|+) :: (Buildable a, FromBuilder b) => a -> Builder -> b infixr 1 |+ -- | Concatenate, then convert. (+||) :: (FromBuilder b) => Builder -> Builder -> b infixr 1 +|| -- | show and concatenate, then convert. (||+) :: (Show a, FromBuilder b) => a -> Builder -> b infixr 1 ||+ (|++|) :: (Buildable a, FromBuilder b) => a -> Builder -> b infixr 1 |++| (||++||) :: (Show a, FromBuilder b) => a -> Builder -> b infixr 1 ||++|| (||++|) :: (Buildable a, FromBuilder b) => a -> Builder -> b infixr 1 ||++| (|++||) :: (Show a, FromBuilder b) => a -> Builder -> b infixr 1 |++|| -- | fmt converts things to String, Text or -- Builder. -- -- Most of the time you won't need it, as strings produced with -- (+|) and (|+) can already be used as String, -- Text, etc. However, combinators like listF can only -- produce Builder (for better type inference), and you need to -- use fmt on them. -- -- Also, fmt can do printing: -- --
--   >>> fmt "Hello world!\n"
--   Hello world!
--   
fmt :: FromBuilder b => Builder -> b -- | Like fmt, but appends a newline. fmtLn :: FromBuilder b => Builder -> b instance Fmt.Internal.Core.FromBuilder Data.Text.Internal.Builder.Builder instance a ~ GHC.Types.Char => Fmt.Internal.Core.FromBuilder [a] instance Fmt.Internal.Core.FromBuilder Data.Text.Internal.Text instance Fmt.Internal.Core.FromBuilder Data.Text.Internal.Lazy.Text instance a ~ () => Fmt.Internal.Core.FromBuilder (GHC.Types.IO a) module Fmt.Internal.Formatters -- | Indent a block of text. -- --
--   >>> fmt $ "This is a list:\n" <> indentF 4 (blockListF [1,2,3])
--   This is a list:
--       - 1
--       - 2
--       - 3
--   
-- -- The output will always end with a newline, even when the input -- doesn't. indentF :: Int -> Builder -> Builder -- | Add a prefix to the first line, and indent all lines but the first -- one. -- -- The output will always end with a newline, even when the input -- doesn't. indentF' :: Int -> Text -> Builder -> Builder -- | Attach a name to anything: -- --
--   >>> fmt $ nameF "clients" $ blockListF ["Alice", "Bob", "Zalgo"]
--   clients:
--     - Alice
--     - Bob
--     - Zalgo
--   
nameF :: Builder -> Builder -> Builder -- | Put words between elements. -- --
--   >>> fmt $ unwordsF ["hello", "world"]
--   hello world
--   
-- -- Of course, it works on anything Buildable: -- --
--   >>> fmt $ unwordsF [1, 2]
--   1 2
--   
unwordsF :: (Foldable f, Buildable a) => f a -> Builder -- | Arrange elements on separate lines. -- --
--   >>> fmt $ unlinesF ["hello", "world"]
--   hello
--   world
--   
unlinesF :: (Foldable f, Buildable a) => f a -> Builder -- | A simple comma-separated list formatter. -- --
--   >>> listF ["hello", "world"]
--   "[hello, world]"
--   
-- -- For multiline output, use jsonListF. listF :: (Foldable f, Buildable a) => f a -> Builder -- | A version of listF that lets you supply your own building -- function for list elements. -- -- For instance, to format a list of lists you'd have to do this (since -- there's no Buildable instance for lists): -- --
--   >>> listF' listF [[1,2,3],[4,5,6]]
--   "[[1, 2, 3], [4, 5, 6]]"
--   
listF' :: (Foldable f) => (a -> Builder) -> f a -> Builder -- | A multiline formatter for lists. -- --
--   >>> fmt $ blockListF [1,2,3]
--   - 1
--   - 2
--   - 3
--   
-- -- Multi-line elements are indented correctly: -- --
--   >>> fmt $ blockListF ["hello\nworld", "foo\nbar\nquix"]
--   - hello
--     world
--   - foo
--     bar
--     quix
--   
blockListF :: forall f a. (Foldable f, Buildable a) => f a -> Builder -- | A version of blockListF that lets you supply your own building -- function for list elements (instead of build) and choose the -- bullet character (instead of "-"). blockListF' :: forall f a. Foldable f => Text -> (a -> Builder) -> f a -> Builder -- | A JSON-style formatter for lists. -- --
--   >>> fmt $ jsonListF [1,2,3]
--   [
--     1
--   , 2
--   , 3
--   ]
--   
-- -- Like blockListF, it handles multiline elements well: -- --
--   >>> fmt $ jsonListF ["hello\nworld", "foo\nbar\nquix"]
--   [
--     hello
--     world
--   , foo
--     bar
--     quix
--   ]
--   
jsonListF :: forall f a. (Foldable f, Buildable a) => f a -> Builder -- | A version of jsonListF that lets you supply your own building -- function for list elements. jsonListF' :: forall f a. (Foldable f) => (a -> Builder) -> f a -> Builder -- | A simple JSON-like map formatter; works for Map, HashMap, etc, as well -- as ordinary lists of pairs. -- --
--   >>> mapF [("a", 1), ("b", 4)]
--   "{a: 1, b: 4}"
--   
-- -- For multiline output, use jsonMapF. mapF :: (IsList t, Item t ~ (k, v), Buildable k, Buildable v) => t -> Builder -- | A version of mapF that lets you supply your own building -- function for keys and values. mapF' :: (IsList t, Item t ~ (k, v)) => (k -> Builder) -> (v -> Builder) -> t -> Builder -- | A YAML-like map formatter: -- --
--   >>> fmt $ blockMapF [("Odds", blockListF [1,3]), ("Evens", blockListF [2,4])]
--   Odds:
--     - 1
--     - 3
--   Evens:
--     - 2
--     - 4
--   
blockMapF :: (IsList t, Item t ~ (k, v), Buildable k, Buildable v) => t -> Builder -- | A version of blockMapF that lets you supply your own building -- function for keys and values. blockMapF' :: (IsList t, Item t ~ (k, v)) => (k -> Builder) -> (v -> Builder) -> t -> Builder -- | A JSON-like map formatter (unlike mapF, always multiline): -- --
--   >>> fmt $ jsonMapF [("Odds", jsonListF [1,3]), ("Evens", jsonListF [2,4])]
--   {
--     Odds:
--       [
--         1
--       , 3
--       ]
--   , Evens:
--       [
--         2
--       , 4
--       ]
--   }
--   
jsonMapF :: (IsList t, Item t ~ (k, v), Buildable k, Buildable v) => t -> Builder -- | A version of jsonMapF that lets you supply your own building -- function for keys and values. jsonMapF' :: forall t k v. (IsList t, Item t ~ (k, v)) => (k -> Builder) -> (v -> Builder) -> t -> Builder -- | Like build for Maybe, but displays Nothing as -- <Nothing> instead of an empty string. -- -- build: -- --
--   >>> build (Nothing :: Maybe Int)
--   ""
--   
--   >>> build (Just 1 :: Maybe Int)
--   "1"
--   
-- -- maybeF: -- --
--   >>> maybeF (Nothing :: Maybe Int)
--   "<Nothing>"
--   
--   >>> maybeF (Just 1 :: Maybe Int)
--   "1"
--   
maybeF :: Buildable a => Maybe a -> Builder -- | Format an Either: -- --
--   >>> eitherF (Right 1 :: Either Bool Int)
--   "<Right: 1>"
--   
eitherF :: (Buildable a, Buildable b) => Either a b -> Builder -- | Take the first N characters: -- --
--   >>> prefixF 3 "hello"
--   "hel"
--   
prefixF :: Buildable a => Int -> a -> Builder -- | Take the last N characters: -- --
--   >>> suffixF 3 "hello"
--   "llo"
--   
suffixF :: Buildable a => Int -> a -> Builder -- | padLeftF n c pads the string with character c from -- the left side until it becomes n characters wide (and does -- nothing if the string is already that long, or longer): -- --
--   >>> padLeftF 5 '0' 12
--   "00012"
--   
--   >>> padLeftF 5 '0' 123456
--   "123456"
--   
padLeftF :: Buildable a => Int -> Char -> a -> Builder -- | padRightF n c pads the string with character c from -- the right side until it becomes n characters wide (and does -- nothing if the string is already that long, or longer): -- --
--   >>> padRightF 5 ' ' "foo"
--   "foo  "
--   
--   >>> padRightF 5 ' ' "foobar"
--   "foobar"
--   
padRightF :: Buildable a => Int -> Char -> a -> Builder -- | padBothF n c pads the string with character c from -- both sides until it becomes n characters wide (and does -- nothing if the string is already that long, or longer): -- --
--   >>> padBothF 5 '=' "foo"
--   "=foo="
--   
--   >>> padBothF 5 '=' "foobar"
--   "foobar"
--   
-- -- When padding can't be distributed equally, the left side is preferred: -- --
--   >>> padBothF 8 '=' "foo"
--   "===foo=="
--   
padBothF :: Buildable a => Int -> Char -> a -> Builder -- | Display something only if the condition is True (empty string -- otherwise). -- -- Note that it can only take a Builder (because otherwise it -- would be unusable with (+|)-formatted strings which can resolve -- to any FromBuilder). You can use build to convert any -- value to a Builder. whenF :: Bool -> Builder -> Builder -- | Display something only if the condition is False (empty string -- otherwise). unlessF :: Bool -> Builder -> Builder module Fmt.Internal.Numeric -- | Format a number as octal: -- --
--   >>> listF' octF [7,8,9,10]
--   "[7, 10, 11, 12]"
--   
octF :: Integral a => a -> Builder -- | Format a number as binary: -- --
--   >>> listF' binF [7,8,9,10]
--   "[111, 1000, 1001, 1010]"
--   
binF :: Integral a => a -> Builder -- | Format a number in arbitrary base (up to 36): -- --
--   >>> baseF 3 10000
--   "111201101"
--   
--   >>> baseF 7 10000
--   "41104"
--   
--   >>> baseF 36 10000
--   "7ps"
--   
baseF :: Integral a => Int -> a -> Builder -- | Format a floating-point number: -- --
--   >>> floatF 3.1415
--   "3.1415"
--   
-- -- Numbers smaller than 1e-6 or bigger-or-equal to 1e21 will be displayed -- using scientific notation: -- --
--   >>> listF' floatF [1e-6,9e-7]
--   "[0.000001, 9.0e-7]"
--   
--   >>> listF' floatF [9e20,1e21]
--   "[900000000000000000000.0, 1.0e21]"
--   
floatF :: Real a => a -> Builder -- | Format a floating-point number using scientific notation, with the -- given amount of decimal places. -- --
--   >>> listF' (exptF 5) [pi,0.1,10]
--   "[3.14159e0, 1.00000e-1, 1.00000e1]"
--   
exptF :: Real a => Int -> a -> Builder -- | Format a floating-point number without scientific notation: -- --
--   >>> listF' (fixedF 5) [pi,0.1,10]
--   "[3.14159, 0.10000, 10.00000]"
--   
fixedF :: Real a => Int -> a -> Builder -- | Break digits in a number: -- --
--   >>> commaizeF 15830000
--   "15,830,000"
--   
commaizeF :: (Buildable a, Integral a) => a -> Builder -- | Add an ordinal suffix to a number: -- --
--   >>> ordinalF 15
--   "15th"
--   
--   >>> ordinalF 22
--   "22nd"
--   
ordinalF :: (Buildable a, Integral a) => a -> Builder groupInt :: (Buildable a, Integral a) => Int -> Char -> a -> Builder atBase :: Integral a => Int -> a -> String showSigned' :: Real a => (a -> ShowS) -> a -> ShowS intToDigit' :: Int -> Char -- | Old-style formatting a la text-format. module Fmt.Internal.Template -- | An old-style formatting function taken from text-format (see -- Data.Text.Format). Unlike format from -- Data.Text.Format, it can produce String and strict -- Text as well (and print to console too). Also it's -- polyvariadic: -- --
--   >>> format "{} + {} = {}" 2 2 4
--   2 + 2 = 4
--   
-- -- You can use arbitrary formatters: -- --
--   >>> format "0x{} + 0x{} = 0x{}" (hexF 130) (hexF 270) (hexF (130+270))
--   0x82 + 0x10e = 0x190
--   
format :: FormatType r => Format -> r -- | Like format, but adds a newline. formatLn :: FormatType r => Format -> r -- | A format string. This is intentionally incompatible with other string -- types, to make it difficult to construct a format string by -- concatenating string fragments (a very common way to accidentally make -- code vulnerable to malicious data). -- -- This type is an instance of IsString, so the easiest way to -- construct a query is to enable the OverloadedStrings language -- extension and then simply write the query in double quotes. -- --
--   {-# LANGUAGE OverloadedStrings #-}
--   
--   import Fmt
--   
--   f :: Format
--   f = "hello {}"
--   
-- -- The underlying type is Text, so literal Haskell strings that -- contain Unicode characters will be correctly handled. newtype Format Format :: Text -> Format [fromFormat] :: Format -> Text -- | Render a format string and arguments to a Builder. renderFormat :: Format -> [Builder] -> Builder zipParams :: [Builder] -> [Builder] -> Builder crack :: Format -> [Builder] -- | Something like PrintfType in Text.Printf. class FormatType r format' :: FormatType r => Format -> [Builder] -> r instance GHC.Show.Show Fmt.Internal.Template.Format instance GHC.Classes.Ord Fmt.Internal.Template.Format instance GHC.Classes.Eq Fmt.Internal.Template.Format instance (Formatting.Buildable.Buildable a, Fmt.Internal.Template.FormatType r) => Fmt.Internal.Template.FormatType (a -> r) instance Fmt.Internal.Core.FromBuilder r => Fmt.Internal.Template.FormatType r instance Data.Semigroup.Semigroup Fmt.Internal.Template.Format instance GHC.Base.Monoid Fmt.Internal.Template.Format instance Data.String.IsString Fmt.Internal.Template.Format module Fmt.Internal.Tuple class TupleF a -- | Format a tuple (of up to 8 elements): -- --
--   >>> tupleF (1,2,"hi")
--   "(1, 2, hi)"
--   
-- -- If any of the elements takes several lines, an alternate format is -- used: -- --
--   >>> fmt $ tupleF ("test","foo\nbar","more test")
--   ( test
--   ,
--     foo
--     bar
--   ,
--     more test )
--   
-- -- You can also use tupleF on lists to get tuple-like formatting. tupleF :: TupleF a => a -> Builder instance (Formatting.Buildable.Buildable a1, Formatting.Buildable.Buildable a2) => Fmt.Internal.Tuple.TupleF (a1, a2) instance (Formatting.Buildable.Buildable a1, Formatting.Buildable.Buildable a2, Formatting.Buildable.Buildable a3) => Fmt.Internal.Tuple.TupleF (a1, a2, a3) instance (Formatting.Buildable.Buildable a1, Formatting.Buildable.Buildable a2, Formatting.Buildable.Buildable a3, Formatting.Buildable.Buildable a4) => Fmt.Internal.Tuple.TupleF (a1, a2, a3, a4) instance (Formatting.Buildable.Buildable a1, Formatting.Buildable.Buildable a2, Formatting.Buildable.Buildable a3, Formatting.Buildable.Buildable a4, Formatting.Buildable.Buildable a5) => Fmt.Internal.Tuple.TupleF (a1, a2, a3, a4, a5) instance (Formatting.Buildable.Buildable a1, Formatting.Buildable.Buildable a2, Formatting.Buildable.Buildable a3, Formatting.Buildable.Buildable a4, Formatting.Buildable.Buildable a5, Formatting.Buildable.Buildable a6) => Fmt.Internal.Tuple.TupleF (a1, a2, a3, a4, a5, a6) instance (Formatting.Buildable.Buildable a1, Formatting.Buildable.Buildable a2, Formatting.Buildable.Buildable a3, Formatting.Buildable.Buildable a4, Formatting.Buildable.Buildable a5, Formatting.Buildable.Buildable a6, Formatting.Buildable.Buildable a7) => Fmt.Internal.Tuple.TupleF (a1, a2, a3, a4, a5, a6, a7) instance (Formatting.Buildable.Buildable a1, Formatting.Buildable.Buildable a2, Formatting.Buildable.Buildable a3, Formatting.Buildable.Buildable a4, Formatting.Buildable.Buildable a5, Formatting.Buildable.Buildable a6, Formatting.Buildable.Buildable a7, Formatting.Buildable.Buildable a8) => Fmt.Internal.Tuple.TupleF (a1, a2, a3, a4, a5, a6, a7, a8) instance Formatting.Buildable.Buildable a => Fmt.Internal.Tuple.TupleF [a] instance Fmt.Internal.Tuple.TupleF [Data.Text.Internal.Builder.Builder] module Fmt.Internal.Generic -- | Format an arbitrary value without requiring a Buildable -- instance: -- --
--   >>> data Foo = Foo { x :: Bool, y :: [Int] } deriving Generic
--   
-- --
--   >>> fmt (genericF (Foo True [1,2,3]))
--   Foo:
--     x: True
--     y: [1, 2, 3]
--   
-- -- It works for non-record constructors too: -- --
--   >>> data Bar = Bar Bool [Int] deriving Generic
--   
-- --
--   >>> fmtLn (genericF (Bar True [1,2,3]))
--   <Bar: True, [1, 2, 3]>
--   
-- -- Any fields inside the type must either be Buildable or one of -- the following types: -- -- -- -- The exact format of genericF might change in future versions, -- so don't rely on it. It's merely a convenience function. genericF :: (Generic a, GBuildable (Rep a)) => a -> Builder class GBuildable f gbuild :: GBuildable f => f a -> Builder -- | A more powerful Buildable used for genericF. Can build -- functions, tuples, lists, maps, etc., as well as combinations thereof. class Buildable' a build' :: Buildable' a => a -> Builder class GetFields f -- | Get fields, together with their names if available getFields :: GetFields f => f a -> [(String, Builder)] instance (Fmt.Internal.Generic.GetFields a, GHC.Generics.Constructor c) => Fmt.Internal.Generic.GBuildable (GHC.Generics.M1 GHC.Generics.C c a) instance (Fmt.Internal.Generic.GetFields a, Fmt.Internal.Generic.GetFields b) => Fmt.Internal.Generic.GetFields (a GHC.Generics.:*: b) instance (Fmt.Internal.Generic.GBuildable a, GHC.Generics.Selector c) => Fmt.Internal.Generic.GetFields (GHC.Generics.M1 GHC.Generics.S c a) instance Fmt.Internal.Generic.GBuildable a => Fmt.Internal.Generic.GetFields (GHC.Generics.M1 GHC.Generics.D c a) instance Fmt.Internal.Generic.GBuildable a => Fmt.Internal.Generic.GetFields (GHC.Generics.M1 GHC.Generics.C c a) instance Fmt.Internal.Generic.GetFields GHC.Generics.U1 instance Fmt.Internal.Generic.Buildable' c => Fmt.Internal.Generic.GBuildable (GHC.Generics.K1 i c) instance Fmt.Internal.Generic.Buildable' () instance (Fmt.Internal.Generic.Buildable' a1, Fmt.Internal.Generic.Buildable' a2) => Fmt.Internal.Generic.Buildable' (a1, a2) instance (Fmt.Internal.Generic.Buildable' a1, Fmt.Internal.Generic.Buildable' a2, Fmt.Internal.Generic.Buildable' a3) => Fmt.Internal.Generic.Buildable' (a1, a2, a3) instance (Fmt.Internal.Generic.Buildable' a1, Fmt.Internal.Generic.Buildable' a2, Fmt.Internal.Generic.Buildable' a3, Fmt.Internal.Generic.Buildable' a4) => Fmt.Internal.Generic.Buildable' (a1, a2, a3, a4) instance (Fmt.Internal.Generic.Buildable' a1, Fmt.Internal.Generic.Buildable' a2, Fmt.Internal.Generic.Buildable' a3, Fmt.Internal.Generic.Buildable' a4, Fmt.Internal.Generic.Buildable' a5) => Fmt.Internal.Generic.Buildable' (a1, a2, a3, a4, a5) instance (Fmt.Internal.Generic.Buildable' a1, Fmt.Internal.Generic.Buildable' a2, Fmt.Internal.Generic.Buildable' a3, Fmt.Internal.Generic.Buildable' a4, Fmt.Internal.Generic.Buildable' a5, Fmt.Internal.Generic.Buildable' a6) => Fmt.Internal.Generic.Buildable' (a1, a2, a3, a4, a5, a6) instance (Fmt.Internal.Generic.Buildable' a1, Fmt.Internal.Generic.Buildable' a2, Fmt.Internal.Generic.Buildable' a3, Fmt.Internal.Generic.Buildable' a4, Fmt.Internal.Generic.Buildable' a5, Fmt.Internal.Generic.Buildable' a6, Fmt.Internal.Generic.Buildable' a7) => Fmt.Internal.Generic.Buildable' (a1, a2, a3, a4, a5, a6, a7) instance (Fmt.Internal.Generic.Buildable' a1, Fmt.Internal.Generic.Buildable' a2, Fmt.Internal.Generic.Buildable' a3, Fmt.Internal.Generic.Buildable' a4, Fmt.Internal.Generic.Buildable' a5, Fmt.Internal.Generic.Buildable' a6, Fmt.Internal.Generic.Buildable' a7, Fmt.Internal.Generic.Buildable' a8) => Fmt.Internal.Generic.Buildable' (a1, a2, a3, a4, a5, a6, a7, a8) instance Fmt.Internal.Generic.Buildable' [GHC.Types.Char] instance Fmt.Internal.Generic.Buildable' a => Fmt.Internal.Generic.Buildable' [a] instance Fmt.Internal.Generic.Buildable' a => Fmt.Internal.Generic.Buildable' (Data.List.NonEmpty.NonEmpty a) instance Fmt.Internal.Generic.Buildable' a => Fmt.Internal.Generic.Buildable' (Data.Sequence.Internal.Seq a) instance (Fmt.Internal.Generic.Buildable' k, Fmt.Internal.Generic.Buildable' v) => Fmt.Internal.Generic.Buildable' (Data.Map.Internal.Map k v) instance Fmt.Internal.Generic.Buildable' v => Fmt.Internal.Generic.Buildable' (Data.Set.Internal.Set v) instance Fmt.Internal.Generic.Buildable' v => Fmt.Internal.Generic.Buildable' (Data.IntMap.Internal.IntMap v) instance Fmt.Internal.Generic.Buildable' Data.IntSet.Internal.IntSet instance Fmt.Internal.Generic.Buildable' a => Fmt.Internal.Generic.Buildable' (GHC.Base.Maybe a) instance (Fmt.Internal.Generic.Buildable' a, Fmt.Internal.Generic.Buildable' b) => Fmt.Internal.Generic.Buildable' (Data.Either.Either a b) instance Fmt.Internal.Generic.Buildable' (a -> b) instance Formatting.Buildable.Buildable a => Fmt.Internal.Generic.Buildable' a instance (Fmt.Internal.Generic.GBuildable a, Fmt.Internal.Generic.GBuildable b) => Fmt.Internal.Generic.GBuildable (a GHC.Generics.:+: b) instance Fmt.Internal.Generic.GBuildable a => Fmt.Internal.Generic.GBuildable (GHC.Generics.M1 GHC.Generics.D d a) -- | A module providing access to internals (in case you really need them). -- Can change at any time, though probably won't. module Fmt.Internal class FormatAsHex a -- | Format a number or bytestring as hex: -- --
--   >>> hexF 3635
--   "e33"
--   
--   >>> hexF ("\0\50\63\80" :: BS.ByteString)
--   "00323f50"
--   
hexF :: FormatAsHex a => a -> Builder class FormatAsBase64 a -- | Convert a bytestring to base64: -- --
--   >>> base64F ("\0\50\63\80" :: BS.ByteString)
--   "ADI/UA=="
--   
base64F :: FormatAsBase64 a => a -> Builder -- | Convert a bytestring to base64url (a variant of base64 which omits -- / and thus can be used in URLs): -- --
--   >>> base64UrlF ("\0\50\63\80" :: BS.ByteString)
--   "ADI_UA=="
--   
base64UrlF :: FormatAsBase64 a => a -> Builder instance Fmt.Internal.FormatAsBase64 Data.ByteString.Internal.ByteString instance Fmt.Internal.FormatAsBase64 Data.ByteString.Lazy.Internal.ByteString instance Fmt.Internal.FormatAsHex Data.ByteString.Internal.ByteString instance Fmt.Internal.FormatAsHex Data.ByteString.Lazy.Internal.ByteString instance GHC.Real.Integral a => Fmt.Internal.FormatAsHex a -- | Formatters for various time types. This module copies the structure of -- Formatting.Time from the formatting -- package. -- -- Most of the time you'll want to use one of these formatters (all of -- the examples below use "2018-02-14 16:20:45.5 CST"): -- -- -- -- Note that two formatters from Formatting.Time are called -- differently here: -- --
--   pico     -> picosecondF
--   decimals -> subsecondF
--   
module Fmt.Time -- | Format time with an arbitrary formatting string. Other formatters in -- this module are implemented using timeF. timeF :: FormatTime a => Text -> a -> Builder -- | Timezone offset on the format -HHMM. -- --
--   >>> t
--   2018-02-14 16:20:45.5 CST
--   
--   >>> tzF t
--   "-0600"
--   
tzF :: FormatTime a => a -> Builder -- | Timezone name. -- --
--   >>> tzNameF t
--   "CST"
--   
tzNameF :: FormatTime a => a -> Builder -- | As dateTimeFmt locale (e.g. %a %b %e %H:%M:%S %Z -- %Y). -- --
--   >>> dateTimeF t
--   "Wed Feb 14 16:20:45 CST 2018"
--   
dateTimeF :: FormatTime a => a -> Builder -- | Same as %H:%M. -- --
--   >>> hmF t
--   "16:20"
--   
hmF :: FormatTime a => a -> Builder -- | Same as %H:%M:%S. -- --
--   >>> hmsF t
--   "16:20:45"
--   
hmsF :: FormatTime a => a -> Builder -- | As timeFmt locale (e.g. %H:%M:%S). -- --
--   >>> hmsLF t
--   "16:20:45"
--   
hmsLF :: FormatTime a => a -> Builder -- | As time12Fmt locale (e.g. %I:%M:%S %p). -- --
--   >>> hmsPLF t
--   "04:20:45 PM"
--   
hmsPLF :: FormatTime a => a -> Builder -- | Day half from (amPm locale), converted to lowercase, -- am, pm. -- --
--   >>> dayHalfF t
--   "pm"
--   
dayHalfF :: FormatTime a => a -> Builder -- | Day half from (amPm locale), AM, PM. -- --
--   >>> dayHalfUF t
--   "PM"
--   
dayHalfUF :: FormatTime a => a -> Builder -- | Hour, 24-hour, leading 0 as needed, 00 - 23. -- --
--   >>> hour24F t
--   "16"
--   
--   >>> hour24F midnight
--   "00"
--   
hour24F :: FormatTime a => a -> Builder -- | Hour, 12-hour, leading 0 as needed, 01 - 12. -- --
--   >>> hour12F t
--   "04"
--   
--   >>> hour12F midnight
--   "12"
--   
hour12F :: FormatTime a => a -> Builder -- | Hour, 24-hour, leading space as needed, 0 - 23. -- --
--   >>> hour24SF t
--   "16"
--   
--   >>> hour24SF midnight
--   " 0"
--   
hour24SF :: FormatTime a => a -> Builder -- | Hour, 12-hour, leading space as needed, 1 - 12. -- --
--   >>> hour12SF t
--   " 4"
--   
--   >>> hour12SF midnight
--   "12"
--   
hour12SF :: FormatTime a => a -> Builder -- | Minute, 00 - 59. -- --
--   >>> minuteF t
--   "20"
--   
minuteF :: FormatTime a => a -> Builder -- | Second, without decimal part, 00 - 60. -- --
--   >>> secondF t
--   "45"
--   
secondF :: FormatTime a => a -> Builder -- | Picosecond, including trailing zeros, 000000000000 - -- 999999999999. -- --
--   >>> picosecondF t
--   "500000000000"
--   
picosecondF :: FormatTime a => a -> Builder -- | Decimal point of the second. Up to 12 digits, without trailing zeros. -- For a whole number of seconds, this produces an empty string. -- --
--   >>> subsecondF t
--   ".5"
--   
subsecondF :: FormatTime a => a -> Builder -- | Number of whole seconds since the Unix epoch. For times before the -- Unix epoch, this is a negative number. Note that in %s.%q and -- %s%Q the decimals are positive, not negative. For example, -- 0.9 seconds before the Unix epoch is formatted as -1.1 with -- %s%Q. -- --
--   >>> epochF t
--   "1518646845"
--   
epochF :: FormatTime a => a -> Builder -- | Same as %m/%d/%y. -- --
--   >>> dateSlashF t
--   "02/14/18"
--   
dateSlashF :: FormatTime a => a -> Builder -- | Same as %Y-%m-%d. -- --
--   >>> dateDashF t
--   "2018-02-14"
--   
dateDashF :: FormatTime a => a -> Builder -- | As dateFmt locale (e.g. %m/%d/%y). -- --
--   >>> dateSlashLF t
--   "02/14/18"
--   
dateSlashLF :: FormatTime a => a -> Builder -- | Year. -- --
--   >>> yearF t
--   "2018"
--   
yearF :: FormatTime a => a -> Builder -- | Last two digits of year, 00 - 99. -- --
--   >>> yyF t
--   "18"
--   
yyF :: FormatTime a => a -> Builder -- | Century (being the first two digits of the year), 00 - -- 99. -- --
--   >>> centuryF t
--   "20"
--   
centuryF :: FormatTime a => a -> Builder -- | Month name, long form (fst from months locale), -- January - December. -- --
--   >>> monthNameF t
--   "February"
--   
monthNameF :: FormatTime a => a -> Builder -- | Month name, short form (snd from months -- locale), Jan - Dec. -- --
--   >>> monthNameShortF t
--   "Feb"
--   
monthNameShortF :: FormatTime a => a -> Builder -- | Month of year, leading 0 as needed, 01 - 12. -- --
--   >>> monthF t
--   "02"
--   
monthF :: FormatTime a => a -> Builder -- | Day of month, leading 0 as needed, 01 - 31. -- --
--   >>> dayOfMonthF t
--   "14"
--   
dayOfMonthF :: FormatTime a => a -> Builder -- | Day of month, 1st, 2nd, 25th, etc. -- --
--   >>> dayOfMonthOrdF t
--   "14th"
--   
dayOfMonthOrdF :: FormatTime a => a -> Builder -- | Day of month, leading space as needed, 1 - 31. dayOfMonthSF :: FormatTime a => a -> Builder -- | Day of year for Ordinal Date format, 001 - 366. -- --
--   >>> dayF t
--   "045"
--   
dayF :: FormatTime a => a -> Builder -- | Year for Week Date format e.g. 2013. -- --
--   >>> weekYearF t
--   "2018"
--   
weekYearF :: FormatTime a => a -> Builder -- | Last two digits of year for Week Date format, 00 - -- 99. -- --
--   >>> weekYYF t
--   "18"
--   
weekYYF :: FormatTime a => a -> Builder -- | Century (first two digits of year) for Week Date format, 00 - -- 99. -- --
--   >>> weekCenturyF t
--   "20"
--   
weekCenturyF :: FormatTime a => a -> Builder -- | Week for Week Date format, 01 - 53. -- --
--   >>> weekF t
--   "07"
--   
weekF :: FormatTime a => a -> Builder -- | Day for Week Date format, 1 - 7. -- --
--   >>> dayOfWeekF t
--   "3"
--   
dayOfWeekF :: FormatTime a => a -> Builder -- | Day of week, short form (snd from wDays -- locale), Sun - Sat. -- --
--   >>> dayNameShortF t
--   "Wed"
--   
dayNameShortF :: FormatTime a => a -> Builder -- | Day of week, long form (fst from wDays locale), -- Sunday - Saturday. -- --
--   >>> dayNameF t
--   "Wednesday"
--   
dayNameF :: FormatTime a => a -> Builder -- | Week number of year, where weeks start on Sunday (as -- sundayStartWeek), 00 - 53. -- --
--   >>> weekFromZeroF t
--   "06"
--   
weekFromZeroF :: FormatTime a => a -> Builder -- | Day of week number, 0 (= Sunday) - 6 (= Saturday). -- --
--   >>> dayOfWeekFromZeroF t
--   "3"
--   
dayOfWeekFromZeroF :: FormatTime a => a -> Builder -- | Week number of year, where weeks start on Monday (as -- mondayStartWeek), 00 - 53. -- --
--   >>> weekOfYearMonF t
--   "07"
--   
weekOfYearMonF :: FormatTime a => a -> Builder -- | Display a time span as one time relative to another. Input is assumed -- to be seconds. Typical inputs are NominalDiffTime and -- DiffTime. -- --
--   >>> diffF False 100
--   "a minute"
--   
--   >>> diffF True 100
--   "in a minute"
--   
diffF :: forall n. RealFrac n => Bool -> n -> Builder -- | Display the absolute value time span in years. -- --
--   >>> epochF t    -- time passed since Jan 1, 1970
--   "1518646845"
--   
--   >>> yearsF 3 1518646845
--   "48.156"
--   
yearsF :: RealFrac n => Int -> n -> Builder -- | Display the absolute value time span in days. -- --
--   >>> daysF 3 1518646845
--   "17576.931"
--   
daysF :: RealFrac n => Int -> n -> Builder -- | Display the absolute value time span in hours. -- --
--   >>> hoursF 3 3600
--   "1.000"
--   
hoursF :: RealFrac n => Int -> n -> Builder -- | Display the absolute value time span in minutes. -- --
--   >>> minutesF 3 150
--   "2.500"
--   
minutesF :: RealFrac n => Int -> n -> Builder -- | Display the absolute value time span in seconds. -- --
--   >>> secondsF 3 100
--   "100.000"
--   
secondsF :: RealFrac n => Int -> n -> Builder module Fmt -- | Concatenate, then convert. (+|) :: (FromBuilder b) => Builder -> Builder -> b infixr 1 +| -- | build and concatenate, then convert. (|+) :: (Buildable a, FromBuilder b) => a -> Builder -> b infixr 1 |+ -- | Concatenate, then convert. (+||) :: (FromBuilder b) => Builder -> Builder -> b infixr 1 +|| -- | show and concatenate, then convert. (||+) :: (Show a, FromBuilder b) => a -> Builder -> b infixr 1 ||+ (|++|) :: (Buildable a, FromBuilder b) => a -> Builder -> b infixr 1 |++| (||++||) :: (Show a, FromBuilder b) => a -> Builder -> b infixr 1 ||++|| (|++||) :: (Show a, FromBuilder b) => a -> Builder -> b infixr 1 |++|| (||++|) :: (Buildable a, FromBuilder b) => a -> Builder -> b infixr 1 ||++| -- | An old-style formatting function taken from text-format (see -- Data.Text.Format). Unlike format from -- Data.Text.Format, it can produce String and strict -- Text as well (and print to console too). Also it's -- polyvariadic: -- --
--   >>> format "{} + {} = {}" 2 2 4
--   2 + 2 = 4
--   
-- -- You can use arbitrary formatters: -- --
--   >>> format "0x{} + 0x{} = 0x{}" (hexF 130) (hexF 270) (hexF (130+270))
--   0x82 + 0x10e = 0x190
--   
format :: FormatType r => Format -> r -- | Like format, but adds a newline. formatLn :: FormatType r => Format -> r -- | A format string. This is intentionally incompatible with other string -- types, to make it difficult to construct a format string by -- concatenating string fragments (a very common way to accidentally make -- code vulnerable to malicious data). -- -- This type is an instance of IsString, so the easiest way to -- construct a query is to enable the OverloadedStrings language -- extension and then simply write the query in double quotes. -- --
--   {-# LANGUAGE OverloadedStrings #-}
--   
--   import Fmt
--   
--   f :: Format
--   f = "hello {}"
--   
-- -- The underlying type is Text, so literal Haskell strings that -- contain Unicode characters will be correctly handled. data Format -- | fmt converts things to String, Text or -- Builder. -- -- Most of the time you won't need it, as strings produced with -- (+|) and (|+) can already be used as String, -- Text, etc. However, combinators like listF can only -- produce Builder (for better type inference), and you need to -- use fmt on them. -- -- Also, fmt can do printing: -- --
--   >>> fmt "Hello world!\n"
--   Hello world!
--   
fmt :: FromBuilder b => Builder -> b -- | Like fmt, but appends a newline. fmtLn :: FromBuilder b => Builder -> b -- | A Builder is an efficient way to build lazy Text -- values. There are several functions for constructing builders, but -- only one to inspect them: to extract any data, you have to turn them -- into lazy Text values using toLazyText. -- -- Internally, a builder constructs a lazy Text by filling -- arrays piece by piece. As each buffer is filled, it is 'popped' off, -- to become a new chunk of the resulting lazy Text. All this is -- hidden from the user of the Builder. data Builder :: * -- | The class of types that can be rendered to a Builder. class Buildable p build :: Buildable p => p -> Builder -- | Indent a block of text. -- --
--   >>> fmt $ "This is a list:\n" <> indentF 4 (blockListF [1,2,3])
--   This is a list:
--       - 1
--       - 2
--       - 3
--   
-- -- The output will always end with a newline, even when the input -- doesn't. indentF :: Int -> Builder -> Builder -- | Add a prefix to the first line, and indent all lines but the first -- one. -- -- The output will always end with a newline, even when the input -- doesn't. indentF' :: Int -> Text -> Builder -> Builder -- | Attach a name to anything: -- --
--   >>> fmt $ nameF "clients" $ blockListF ["Alice", "Bob", "Zalgo"]
--   clients:
--     - Alice
--     - Bob
--     - Zalgo
--   
nameF :: Builder -> Builder -> Builder -- | Put words between elements. -- --
--   >>> fmt $ unwordsF ["hello", "world"]
--   hello world
--   
-- -- Of course, it works on anything Buildable: -- --
--   >>> fmt $ unwordsF [1, 2]
--   1 2
--   
unwordsF :: (Foldable f, Buildable a) => f a -> Builder -- | Arrange elements on separate lines. -- --
--   >>> fmt $ unlinesF ["hello", "world"]
--   hello
--   world
--   
unlinesF :: (Foldable f, Buildable a) => f a -> Builder -- | A simple comma-separated list formatter. -- --
--   >>> listF ["hello", "world"]
--   "[hello, world]"
--   
-- -- For multiline output, use jsonListF. listF :: (Foldable f, Buildable a) => f a -> Builder -- | A version of listF that lets you supply your own building -- function for list elements. -- -- For instance, to format a list of lists you'd have to do this (since -- there's no Buildable instance for lists): -- --
--   >>> listF' listF [[1,2,3],[4,5,6]]
--   "[[1, 2, 3], [4, 5, 6]]"
--   
listF' :: (Foldable f) => (a -> Builder) -> f a -> Builder -- | A multiline formatter for lists. -- --
--   >>> fmt $ blockListF [1,2,3]
--   - 1
--   - 2
--   - 3
--   
-- -- Multi-line elements are indented correctly: -- --
--   >>> fmt $ blockListF ["hello\nworld", "foo\nbar\nquix"]
--   - hello
--     world
--   - foo
--     bar
--     quix
--   
blockListF :: forall f a. (Foldable f, Buildable a) => f a -> Builder -- | A version of blockListF that lets you supply your own building -- function for list elements (instead of build) and choose the -- bullet character (instead of "-"). blockListF' :: forall f a. Foldable f => Text -> (a -> Builder) -> f a -> Builder -- | A JSON-style formatter for lists. -- --
--   >>> fmt $ jsonListF [1,2,3]
--   [
--     1
--   , 2
--   , 3
--   ]
--   
-- -- Like blockListF, it handles multiline elements well: -- --
--   >>> fmt $ jsonListF ["hello\nworld", "foo\nbar\nquix"]
--   [
--     hello
--     world
--   , foo
--     bar
--     quix
--   ]
--   
jsonListF :: forall f a. (Foldable f, Buildable a) => f a -> Builder -- | A version of jsonListF that lets you supply your own building -- function for list elements. jsonListF' :: forall f a. (Foldable f) => (a -> Builder) -> f a -> Builder -- | A simple JSON-like map formatter; works for Map, HashMap, etc, as well -- as ordinary lists of pairs. -- --
--   >>> mapF [("a", 1), ("b", 4)]
--   "{a: 1, b: 4}"
--   
-- -- For multiline output, use jsonMapF. mapF :: (IsList t, Item t ~ (k, v), Buildable k, Buildable v) => t -> Builder -- | A version of mapF that lets you supply your own building -- function for keys and values. mapF' :: (IsList t, Item t ~ (k, v)) => (k -> Builder) -> (v -> Builder) -> t -> Builder -- | A YAML-like map formatter: -- --
--   >>> fmt $ blockMapF [("Odds", blockListF [1,3]), ("Evens", blockListF [2,4])]
--   Odds:
--     - 1
--     - 3
--   Evens:
--     - 2
--     - 4
--   
blockMapF :: (IsList t, Item t ~ (k, v), Buildable k, Buildable v) => t -> Builder -- | A version of blockMapF that lets you supply your own building -- function for keys and values. blockMapF' :: (IsList t, Item t ~ (k, v)) => (k -> Builder) -> (v -> Builder) -> t -> Builder -- | A JSON-like map formatter (unlike mapF, always multiline): -- --
--   >>> fmt $ jsonMapF [("Odds", jsonListF [1,3]), ("Evens", jsonListF [2,4])]
--   {
--     Odds:
--       [
--         1
--       , 3
--       ]
--   , Evens:
--       [
--         2
--       , 4
--       ]
--   }
--   
jsonMapF :: (IsList t, Item t ~ (k, v), Buildable k, Buildable v) => t -> Builder -- | A version of jsonMapF that lets you supply your own building -- function for keys and values. jsonMapF' :: forall t k v. (IsList t, Item t ~ (k, v)) => (k -> Builder) -> (v -> Builder) -> t -> Builder -- | Format a tuple (of up to 8 elements): -- --
--   >>> tupleF (1,2,"hi")
--   "(1, 2, hi)"
--   
-- -- If any of the elements takes several lines, an alternate format is -- used: -- --
--   >>> fmt $ tupleF ("test","foo\nbar","more test")
--   ( test
--   ,
--     foo
--     bar
--   ,
--     more test )
--   
-- -- You can also use tupleF on lists to get tuple-like formatting. tupleF :: TupleF a => a -> Builder -- | Like build for Maybe, but displays Nothing as -- <Nothing> instead of an empty string. -- -- build: -- --
--   >>> build (Nothing :: Maybe Int)
--   ""
--   
--   >>> build (Just 1 :: Maybe Int)
--   "1"
--   
-- -- maybeF: -- --
--   >>> maybeF (Nothing :: Maybe Int)
--   "<Nothing>"
--   
--   >>> maybeF (Just 1 :: Maybe Int)
--   "1"
--   
maybeF :: Buildable a => Maybe a -> Builder -- | Format an Either: -- --
--   >>> eitherF (Right 1 :: Either Bool Int)
--   "<Right: 1>"
--   
eitherF :: (Buildable a, Buildable b) => Either a b -> Builder -- | Take the first N characters: -- --
--   >>> prefixF 3 "hello"
--   "hel"
--   
prefixF :: Buildable a => Int -> a -> Builder -- | Take the last N characters: -- --
--   >>> suffixF 3 "hello"
--   "llo"
--   
suffixF :: Buildable a => Int -> a -> Builder -- | padLeftF n c pads the string with character c from -- the left side until it becomes n characters wide (and does -- nothing if the string is already that long, or longer): -- --
--   >>> padLeftF 5 '0' 12
--   "00012"
--   
--   >>> padLeftF 5 '0' 123456
--   "123456"
--   
padLeftF :: Buildable a => Int -> Char -> a -> Builder -- | padRightF n c pads the string with character c from -- the right side until it becomes n characters wide (and does -- nothing if the string is already that long, or longer): -- --
--   >>> padRightF 5 ' ' "foo"
--   "foo  "
--   
--   >>> padRightF 5 ' ' "foobar"
--   "foobar"
--   
padRightF :: Buildable a => Int -> Char -> a -> Builder -- | padBothF n c pads the string with character c from -- both sides until it becomes n characters wide (and does -- nothing if the string is already that long, or longer): -- --
--   >>> padBothF 5 '=' "foo"
--   "=foo="
--   
--   >>> padBothF 5 '=' "foobar"
--   "foobar"
--   
-- -- When padding can't be distributed equally, the left side is preferred: -- --
--   >>> padBothF 8 '=' "foo"
--   "===foo=="
--   
padBothF :: Buildable a => Int -> Char -> a -> Builder -- | Format a number or bytestring as hex: -- --
--   >>> hexF 3635
--   "e33"
--   
--   >>> hexF ("\0\50\63\80" :: BS.ByteString)
--   "00323f50"
--   
hexF :: FormatAsHex a => a -> Builder -- | Convert a bytestring to base64: -- --
--   >>> base64F ("\0\50\63\80" :: BS.ByteString)
--   "ADI/UA=="
--   
base64F :: FormatAsBase64 a => a -> Builder -- | Convert a bytestring to base64url (a variant of base64 which omits -- / and thus can be used in URLs): -- --
--   >>> base64UrlF ("\0\50\63\80" :: BS.ByteString)
--   "ADI_UA=="
--   
base64UrlF :: FormatAsBase64 a => a -> Builder -- | Add an ordinal suffix to a number: -- --
--   >>> ordinalF 15
--   "15th"
--   
--   >>> ordinalF 22
--   "22nd"
--   
ordinalF :: (Buildable a, Integral a) => a -> Builder -- | Break digits in a number: -- --
--   >>> commaizeF 15830000
--   "15,830,000"
--   
commaizeF :: (Buildable a, Integral a) => a -> Builder -- | Format a number as octal: -- --
--   >>> listF' octF [7,8,9,10]
--   "[7, 10, 11, 12]"
--   
octF :: Integral a => a -> Builder -- | Format a number as binary: -- --
--   >>> listF' binF [7,8,9,10]
--   "[111, 1000, 1001, 1010]"
--   
binF :: Integral a => a -> Builder -- | Format a number in arbitrary base (up to 36): -- --
--   >>> baseF 3 10000
--   "111201101"
--   
--   >>> baseF 7 10000
--   "41104"
--   
--   >>> baseF 36 10000
--   "7ps"
--   
baseF :: Integral a => Int -> a -> Builder -- | Format a floating-point number: -- --
--   >>> floatF 3.1415
--   "3.1415"
--   
-- -- Numbers smaller than 1e-6 or bigger-or-equal to 1e21 will be displayed -- using scientific notation: -- --
--   >>> listF' floatF [1e-6,9e-7]
--   "[0.000001, 9.0e-7]"
--   
--   >>> listF' floatF [9e20,1e21]
--   "[900000000000000000000.0, 1.0e21]"
--   
floatF :: Real a => a -> Builder -- | Format a floating-point number using scientific notation, with the -- given amount of decimal places. -- --
--   >>> listF' (exptF 5) [pi,0.1,10]
--   "[3.14159e0, 1.00000e-1, 1.00000e1]"
--   
exptF :: Real a => Int -> a -> Builder -- | Format a floating-point number without scientific notation: -- --
--   >>> listF' (fixedF 5) [pi,0.1,10]
--   "[3.14159, 0.10000, 10.00000]"
--   
fixedF :: Real a => Int -> a -> Builder -- | Display something only if the condition is True (empty string -- otherwise). -- -- Note that it can only take a Builder (because otherwise it -- would be unusable with (+|)-formatted strings which can resolve -- to any FromBuilder). You can use build to convert any -- value to a Builder. whenF :: Bool -> Builder -> Builder -- | Display something only if the condition is False (empty string -- otherwise). unlessF :: Bool -> Builder -> Builder -- | Format an arbitrary value without requiring a Buildable -- instance: -- --
--   >>> data Foo = Foo { x :: Bool, y :: [Int] } deriving Generic
--   
-- --
--   >>> fmt (genericF (Foo True [1,2,3]))
--   Foo:
--     x: True
--     y: [1, 2, 3]
--   
-- -- It works for non-record constructors too: -- --
--   >>> data Bar = Bar Bool [Int] deriving Generic
--   
-- --
--   >>> fmtLn (genericF (Bar True [1,2,3]))
--   <Bar: True, [1, 2, 3]>
--   
-- -- Any fields inside the type must either be Buildable or one of -- the following types: -- -- -- -- The exact format of genericF might change in future versions, -- so don't rely on it. It's merely a convenience function. genericF :: (Generic a, GBuildable (Rep a)) => a -> Builder