Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Partially implements the interface provided by the fmt
package on top of
prettyprinter
.
Synopsis
- class Buildable a where
- class FromDoc a where
- class FromSimpleDoc a where
- fmtSimple :: SimpleDocStream ann -> a
- data ReflowingDoc
- pretty :: (Buildable a, FromDoc b) => a -> b
- prettyText :: Buildable a => a -> Text
- (+|) :: FromDoc b => Doc -> Doc -> b
- (|+) :: (Buildable a, FromDoc b) => a -> Doc -> b
- (|++) :: Buildable a => a -> Doc -> ReflowingDoc
- (|++^) :: Buildable a => a -> Doc -> ReflowingDoc
- (++|) :: FromDoc b => Text -> ReflowingDoc -> b
- unlinesF :: (Foldable f, Buildable a) => f a -> Doc
- unwordsF :: (Buildable a, Foldable f) => f a -> Doc
- nameF :: Buildable a => Doc -> a -> Doc
- indentF :: Int -> Doc -> Doc
- blockMapF :: (Buildable k, Buildable v, IsList f, Item f ~ (k, v)) => f -> Doc
- blockMapF' :: (IsList f, Item f ~ (k, v)) => (k -> Doc) -> (v -> Doc) -> f -> Doc
- blockListF :: (Buildable a, Foldable f) => f a -> Doc
- blockListF' :: Foldable f => Doc -> (a -> Doc) -> f a -> Doc
- mapF :: (Buildable k, Buildable v, IsList f, Item f ~ (k, v)) => f -> Doc
- mapF' :: (IsList f, Item f ~ (k, v)) => (k -> Doc) -> (v -> Doc) -> f -> Doc
- listF :: (Buildable a, Foldable f) => f a -> Doc
- listF' :: Foldable f => (a -> Doc) -> f a -> Doc
- whenF :: Bool -> Doc -> Doc
- unlessF :: Bool -> Doc -> Doc
- enumerateF :: [(Text, Doc)] -> Doc
- enumerateF' :: Doc -> [(Text, Doc)] -> Doc
- whenNE :: Monoid a => a -> Doc -> a
- fillSepF :: (Foldable t, Buildable a) => t a -> Doc
- fillSepF' :: (Foldable t, Buildable a) => Doc -> t a -> Doc
- reflowF :: Text -> Doc
- singleLineF :: Buildable a => a -> Doc
- punctuateF :: (Foldable t, Buildable a) => Doc -> Doc -> t a -> [Doc]
- punctuateF' :: (Foldable t, Buildable a) => Doc -> Doc -> Doc -> t a -> [Doc]
- quoteF :: Buildable a => Doc -> a -> Doc
- quoteF' :: Buildable a => Doc -> Doc -> a -> Doc
- quoteOrIndentF :: Buildable a => a -> Doc
- flatAltF :: (a -> Doc) -> (a -> Doc) -> a -> Doc
- class TupleF a where
- class FormatAsHex a where
- newtype Hex a = Hex a
- newtype GenericBuildable a = GenericBuildable a
- class GBuildable f where
- class GetFields f where
Documentation
class Buildable a where Source #
A thing that can be prettyprinted in human-readable (but not necessarily machine-readable) format
Nothing
Make a document with human-readable representation
Instances
Buildable Void Source # | |
Buildable Int16 Source # | |
Buildable Int32 Source # | |
Buildable Int64 Source # | |
Buildable Int8 Source # | |
Buildable Word16 Source # | |
Buildable Word32 Source # | |
Buildable Word64 Source # | |
Buildable Word8 Source # | |
Buildable IntSet Source # |
|
Buildable Doc Source # | |
Buildable Text Source # | Differs from the corresponding
|
Buildable Builder Source # | |
Buildable LText Source # | Differs from the corresponding
|
Buildable Integer Source # | |
Buildable Natural Source # | |
Buildable () Source # | |
Buildable Bool Source # | |
Buildable Char Source # | Differs from the corresponding
|
Buildable Double Source # | |
Buildable Float Source # | |
Buildable Int Source # | |
Buildable Word Source # | |
Buildable a => Buildable (Identity a) Source # | |
Buildable a => Buildable (Ratio a) Source # | |
Buildable v => Buildable (IntMap v) Source # |
|
Buildable v => Buildable (Set v) Source # |
|
(GBuildable (Rep a), Generic a) => Buildable (GenericBuildable a) Source # | |
Defined in Fmt.Buildable build :: GenericBuildable a -> Doc Source # buildList :: [GenericBuildable a] -> Doc Source # | |
Buildable a => Buildable (NonEmpty a) Source # | |
Buildable a => Buildable (Maybe a) Source # | One important quirk of this instance is it skips over
|
Buildable a => Buildable [a] Source # | |
(Buildable a, Buildable b) => Buildable (Either a b) Source # |
|
(Buildable k, Buildable v) => Buildable (Map k v) Source # |
|
(Buildable a1, Buildable a2) => Buildable (a1, a2) Source # | |
Buildable a => Buildable (Const a b) Source # | |
(Buildable a1, Buildable a2, Buildable a3) => Buildable (a1, a2, a3) Source # | |
(Buildable a1, Buildable a2, Buildable a3, Buildable a4) => Buildable (a1, a2, a3, a4) Source # | |
(Buildable a1, Buildable a2, Buildable a3, Buildable a4, Buildable a5) => Buildable (a1, a2, a3, a4, a5) Source # | |
(Buildable a1, Buildable a2, Buildable a3, Buildable a4, Buildable a5, Buildable a6) => Buildable (a1, a2, a3, a4, a5, a6) Source # | |
(Buildable a1, Buildable a2, Buildable a3, Buildable a4, Buildable a5, Buildable a6, Buildable a7) => Buildable (a1, a2, a3, a4, a5, a6, a7) Source # | |
(Buildable a1, Buildable a2, Buildable a3, Buildable a4, Buildable a5, Buildable a6, Buildable a7, Buildable a8) => Buildable (a1, a2, a3, a4, a5, a6, a7, a8) Source # | |
(Buildable a1, Buildable a2, Buildable a3, Buildable a4, Buildable a5, Buildable a6, Buildable a7, Buildable a8, Buildable a9) => Buildable (a1, a2, a3, a4, a5, a6, a7, a8, a9) Source # | |
(Buildable a1, Buildable a2, Buildable a3, Buildable a4, Buildable a5, Buildable a6, Buildable a7, Buildable a8, Buildable a9, Buildable a10) => Buildable (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) Source # | |
(Buildable a1, Buildable a2, Buildable a3, Buildable a4, Buildable a5, Buildable a6, Buildable a7, Buildable a8, Buildable a9, Buildable a10, Buildable a11) => Buildable (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11) Source # | |
(Buildable a1, Buildable a2, Buildable a3, Buildable a4, Buildable a5, Buildable a6, Buildable a7, Buildable a8, Buildable a9, Buildable a10, Buildable a11, Buildable a12) => Buildable (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12) Source # | |
(Buildable a1, Buildable a2, Buildable a3, Buildable a4, Buildable a5, Buildable a6, Buildable a7, Buildable a8, Buildable a9, Buildable a10, Buildable a11, Buildable a12, Buildable a13) => Buildable (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13) Source # | |
(Buildable a1, Buildable a2, Buildable a3, Buildable a4, Buildable a5, Buildable a6, Buildable a7, Buildable a8, Buildable a9, Buildable a10, Buildable a11, Buildable a12, Buildable a13, Buildable a14) => Buildable (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14) Source # | |
(Buildable a1, Buildable a2, Buildable a3, Buildable a4, Buildable a5, Buildable a6, Buildable a7, Buildable a8, Buildable a9, Buildable a10, Buildable a11, Buildable a12, Buildable a13, Buildable a14, Buildable a15) => Buildable (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15) Source # | |
(Buildable a1, Buildable a2, Buildable a3, Buildable a4, Buildable a5, Buildable a6, Buildable a7, Buildable a8, Buildable a9, Buildable a10, Buildable a11, Buildable a12, Buildable a13, Buildable a14, Buildable a15, Buildable a16) => Buildable (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16) Source # | |
(Buildable a1, Buildable a2, Buildable a3, Buildable a4, Buildable a5, Buildable a6, Buildable a7, Buildable a8, Buildable a9, Buildable a10, Buildable a11, Buildable a12, Buildable a13, Buildable a14, Buildable a15, Buildable a16, Buildable a17) => Buildable (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17) Source # | |
(Buildable a1, Buildable a2, Buildable a3, Buildable a4, Buildable a5, Buildable a6, Buildable a7, Buildable a8, Buildable a9, Buildable a10, Buildable a11, Buildable a12, Buildable a13, Buildable a14, Buildable a15, Buildable a16, Buildable a17, Buildable a18) => Buildable (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18) Source # | |
(Buildable a1, Buildable a2, Buildable a3, Buildable a4, Buildable a5, Buildable a6, Buildable a7, Buildable a8, Buildable a9, Buildable a10, Buildable a11, Buildable a12, Buildable a13, Buildable a14, Buildable a15, Buildable a16, Buildable a17, Buildable a18, Buildable a19) => Buildable (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19) Source # | |
(Buildable a1, Buildable a2, Buildable a3, Buildable a4, Buildable a5, Buildable a6, Buildable a7, Buildable a8, Buildable a9, Buildable a10, Buildable a11, Buildable a12, Buildable a13, Buildable a14, Buildable a15, Buildable a16, Buildable a17, Buildable a18, Buildable a19, Buildable a20) => Buildable (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20) Source # | |
(Buildable a1, Buildable a2, Buildable a3, Buildable a4, Buildable a5, Buildable a6, Buildable a7, Buildable a8, Buildable a9, Buildable a10, Buildable a11, Buildable a12, Buildable a13, Buildable a14, Buildable a15, Buildable a16, Buildable a17, Buildable a18, Buildable a19, Buildable a20, Buildable a21) => Buildable (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21) Source # | |
(Buildable a1, Buildable a2, Buildable a3, Buildable a4, Buildable a5, Buildable a6, Buildable a7, Buildable a8, Buildable a9, Buildable a10, Buildable a11, Buildable a12, Buildable a13, Buildable a14, Buildable a15, Buildable a16, Buildable a17, Buildable a18, Buildable a19, Buildable a20, Buildable a21, Buildable a22) => Buildable (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22) Source # | |
(Buildable a1, Buildable a2, Buildable a3, Buildable a4, Buildable a5, Buildable a6, Buildable a7, Buildable a8, Buildable a9, Buildable a10, Buildable a11, Buildable a12, Buildable a13, Buildable a14, Buildable a15, Buildable a16, Buildable a17, Buildable a18, Buildable a19, Buildable a20, Buildable a21, Buildable a22, Buildable a23) => Buildable (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22, a23) Source # | |
(Buildable a1, Buildable a2, Buildable a3, Buildable a4, Buildable a5, Buildable a6, Buildable a7, Buildable a8, Buildable a9, Buildable a10, Buildable a11, Buildable a12, Buildable a13, Buildable a14, Buildable a15, Buildable a16, Buildable a17, Buildable a18, Buildable a19, Buildable a20, Buildable a21, Buildable a22, Buildable a23, Buildable a24) => Buildable (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22, a23, a24) Source # | |
Defined in Fmt.Buildable | |
(Buildable a1, Buildable a2, Buildable a3, Buildable a4, Buildable a5, Buildable a6, Buildable a7, Buildable a8, Buildable a9, Buildable a10, Buildable a11, Buildable a12, Buildable a13, Buildable a14, Buildable a15, Buildable a16, Buildable a17, Buildable a18, Buildable a19, Buildable a20, Buildable a21, Buildable a22, Buildable a23, Buildable a24, Buildable a25) => Buildable (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22, a23, a24, a25) Source # | |
Defined in Fmt.Buildable | |
(Buildable a1, Buildable a2, Buildable a3, Buildable a4, Buildable a5, Buildable a6, Buildable a7, Buildable a8, Buildable a9, Buildable a10, Buildable a11, Buildable a12, Buildable a13, Buildable a14, Buildable a15, Buildable a16, Buildable a17, Buildable a18, Buildable a19, Buildable a20, Buildable a21, Buildable a22, Buildable a23, Buildable a24, Buildable a25, Buildable a26) => Buildable (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22, a23, a24, a25, a26) Source # | |
Defined in Fmt.Buildable | |
(Buildable a1, Buildable a2, Buildable a3, Buildable a4, Buildable a5, Buildable a6, Buildable a7, Buildable a8, Buildable a9, Buildable a10, Buildable a11, Buildable a12, Buildable a13, Buildable a14, Buildable a15, Buildable a16, Buildable a17, Buildable a18, Buildable a19, Buildable a20, Buildable a21, Buildable a22, Buildable a23, Buildable a24, Buildable a25, Buildable a26, Buildable a27) => Buildable (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22, a23, a24, a25, a26, a27) Source # | |
Defined in Fmt.Buildable build :: (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22, a23, a24, a25, a26, a27) -> Doc Source # buildList :: [(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22, a23, a24, a25, a26, a27)] -> Doc Source # | |
(Buildable a1, Buildable a2, Buildable a3, Buildable a4, Buildable a5, Buildable a6, Buildable a7, Buildable a8, Buildable a9, Buildable a10, Buildable a11, Buildable a12, Buildable a13, Buildable a14, Buildable a15, Buildable a16, Buildable a17, Buildable a18, Buildable a19, Buildable a20, Buildable a21, Buildable a22, Buildable a23, Buildable a24, Buildable a25, Buildable a26, Buildable a27, Buildable a28) => Buildable (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22, a23, a24, a25, a26, a27, a28) Source # | |
Defined in Fmt.Buildable build :: (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22, a23, a24, a25, a26, a27, a28) -> Doc Source # buildList :: [(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22, a23, a24, a25, a26, a27, a28)] -> Doc Source # | |
(Buildable a1, Buildable a2, Buildable a3, Buildable a4, Buildable a5, Buildable a6, Buildable a7, Buildable a8, Buildable a9, Buildable a10, Buildable a11, Buildable a12, Buildable a13, Buildable a14, Buildable a15, Buildable a16, Buildable a17, Buildable a18, Buildable a19, Buildable a20, Buildable a21, Buildable a22, Buildable a23, Buildable a24, Buildable a25, Buildable a26, Buildable a27, Buildable a28, Buildable a29) => Buildable (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22, a23, a24, a25, a26, a27, a28, a29) Source # | |
Defined in Fmt.Buildable build :: (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22, a23, a24, a25, a26, a27, a28, a29) -> Doc Source # buildList :: [(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22, a23, a24, a25, a26, a27, a28, a29)] -> Doc Source # | |
(Buildable a1, Buildable a2, Buildable a3, Buildable a4, Buildable a5, Buildable a6, Buildable a7, Buildable a8, Buildable a9, Buildable a10, Buildable a11, Buildable a12, Buildable a13, Buildable a14, Buildable a15, Buildable a16, Buildable a17, Buildable a18, Buildable a19, Buildable a20, Buildable a21, Buildable a22, Buildable a23, Buildable a24, Buildable a25, Buildable a26, Buildable a27, Buildable a28, Buildable a29, Buildable a30) => Buildable (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22, a23, a24, a25, a26, a27, a28, a29, a30) Source # | |
Defined in Fmt.Buildable build :: (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22, a23, a24, a25, a26, a27, a28, a29, a30) -> Doc Source # buildList :: [(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22, a23, a24, a25, a26, a27, a28, a29, a30)] -> Doc Source # |
class FromDoc a where Source #
A class of things that can be produced from Doc
using the default layout
engine. Mostly various text types.
Render a Doc
to another format.
>>>
doc = "foo" :: Doc
>>>
fmt doc :: Text
"foo">>>
fmt doc :: LText
"foo">>>
fmt doc :: String
"foo">>>
fmt doc :: ByteString
"foo">>>
fmt doc :: LByteString
"foo">>>
fmt doc :: IO ()
foo>>>
fmt doc :: Data.Text.Lazy.Builder.Builder
"foo">>>
Data.ByteString.Builder.toLazyByteString (fmt doc :: Data.ByteString.Builder.Builder)
"foo"
Instances
FromDoc Builder Source # | |
FromDoc ByteString Source # | |
Defined in Fmt.Buildable fmt :: Doc -> ByteString Source # | |
FromDoc Doc Source # | |
FromDoc Text Source # | |
FromDoc Builder Source # | |
FromDoc LByteString Source # | |
Defined in Fmt.Buildable fmt :: Doc -> LByteString Source # | |
FromDoc LText Source # | |
FromDoc String Source # | |
a ~ () => FromDoc (IO a) Source # | |
class FromSimpleDoc a where Source #
Helper intermediary class to define FromDoc
. The primary motivation for
its existence is being able to override the default layout engine.
>>>
:{
layoutNarrow = Prettyprinter.layoutPretty $ Prettyprinter.LayoutOptions $ Prettyprinter.AvailablePerLine 20 1 :}
>>>
doc = reflowF "Lorem ipsum dolor sit amet, consectetur adipiscing elit."
>>>
fmt doc
Lorem ipsum dolor sit amet, consectetur adipiscing elit.>>>
fmtSimple $ layoutNarrow doc
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
fmtSimple :: SimpleDocStream ann -> a Source #
Instances
FromSimpleDoc Builder Source # | |
Defined in Fmt.Buildable fmtSimple :: SimpleDocStream ann -> Builder Source # | |
FromSimpleDoc ByteString Source # | |
Defined in Fmt.Buildable fmtSimple :: SimpleDocStream ann -> ByteString Source # | |
FromSimpleDoc Text Source # | |
Defined in Fmt.Buildable fmtSimple :: SimpleDocStream ann -> Text Source # | |
FromSimpleDoc Builder Source # | |
Defined in Fmt.Buildable fmtSimple :: SimpleDocStream ann -> Builder Source # | |
FromSimpleDoc LByteString Source # | |
Defined in Fmt.Buildable fmtSimple :: SimpleDocStream ann -> LByteString Source # | |
FromSimpleDoc LText Source # | |
Defined in Fmt.Buildable fmtSimple :: SimpleDocStream ann -> LText Source # | |
FromSimpleDoc String Source # | |
Defined in Fmt.Buildable fmtSimple :: SimpleDocStream ann -> String Source # | |
a ~ () => FromSimpleDoc (IO a) Source # | |
Defined in Fmt.Buildable fmtSimple :: SimpleDocStream ann -> IO a Source # |
data ReflowingDoc Source #
Opaque type for reflowing brackets ++|
|++
.
Helpers
prettyText :: Buildable a => a -> Text Source #
A less polymorphic version of pretty
for convenience.
Brackets
(+|) :: FromDoc b => Doc -> Doc -> b infixr 1 Source #
Left format bracket. Enclose the value to format in these for concise syntax:
>>>
:{
data WorldType = Cruel | Wonderful deriving (Generic, Buildable) :}
>>>
sayHello worldType = "Hello, " +| worldType |+ " world!"
>>>
sayHello Cruel
Hello, Cruel world!>>>
sayHello Wonderful
Hello, Wonderful world!
(|++) :: Buildable a => a -> Doc -> ReflowingDoc infixr 1 Source #
Bracket versions of enumerateF
. Note that unlike with |+
, both brackets
are required.
>>>
let splice = "lorem posuere dapibus in ut lorem." :: Doc
>>>
let long_splice = splice <> " " <> splice
>>>
:{
"Lorem ipsum dolor sit amet, consectetur adipiscing elit." ++| splice |++ "Morbi aliquet accumsan libero." ++| long_splice |++ "Consectetur adipiscing elit." :} Lorem ipsum dolor sit amet, consectetur adipiscing elit. lorem posuere dapibus in ut lorem. Morbi aliquet accumsan libero. lorem posuere dapibus in ut lorem. lorem posuere dapibus in ut lorem. Consectetur adipiscing elit.
>>>
let splice = build "lorem\nposuere\ndapibus"
>>>
:{
"Lorem ipsum dolor sit amet, consectetur adipiscing elit." ++| splice |++ "Morbi aliquet accumsan libero." :} Lorem ipsum dolor sit amet, consectetur adipiscing elit. lorem posuere dapibus Morbi aliquet accumsan libero.
(|++^) :: Buildable a => a -> Doc -> ReflowingDoc infixr 1 Source #
A version of the reflowing bracket that always breaks after a splice if there's a break before the splice.
Compare with the similar example for |++
, notice the line break after
splice
. It may be combined with quoteOrIndentF
.
>>>
let splice = "lorem posuere dapibus in ut lorem." :: Doc
>>>
let long_splice = splice <> " " <> splice
>>>
:{
"Lorem ipsum dolor sit amet, consectetur adipiscing elit." ++| splice |++^ "Morbi aliquet accumsan libero." ++| long_splice |++^ "Consectetur adipiscing elit." :} Lorem ipsum dolor sit amet, consectetur adipiscing elit. lorem posuere dapibus in ut lorem. Morbi aliquet accumsan libero. lorem posuere dapibus in ut lorem. lorem posuere dapibus in ut lorem. Consectetur adipiscing elit.
Formatters
unlinesF :: (Foldable f, Buildable a) => f a -> Doc Source #
Join a Foldable
with hardlines.
>>>
Prettyprinter.group $ unlinesF ["foo", "bar", "baz"]
foo bar baz
unwordsF :: (Buildable a, Foldable f) => f a -> Doc Source #
Join a Foldable
with spaces.
>>>
unwordsF ["foo", "bar", "baz"]
foo bar baz
nameF :: Buildable a => Doc -> a -> Doc Source #
If name
and content
fit into the page width and content
doesn't
contain hard line breaks, layout as single line with :
between. Otherwise,
make a multiline layout, appending :
to name
, and nesting content
by 2
spaces.
>>>
nameF "Test" "foo"
Test: foo>>>
nameF "Test" $ fillSepF $ replicate 27 "foo"
Test: foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo
If either name or content is empty, returns only the other one.
>>>
nameF "" "foo"
foo>>>
nameF "Test" ""
Test
indentF :: Int -> Doc -> Doc Source #
Indent Doc
by a given number of spaces.
>>>
indentF 4 "foo"
foo>>>
indentF 4 "foo\nbar"
foo bar
blockMapF :: (Buildable k, Buildable v, IsList f, Item f ~ (k, v)) => f -> Doc Source #
Print a map-like thing in the style of a YAML map.
>>>
blockMapF $ [("foo", "bar"), ("baz", "quux")]
foo: bar baz: quux>>>
blockMapF ([] :: [(Text, Text)])
{}
blockMapF' :: (IsList f, Item f ~ (k, v)) => (k -> Doc) -> (v -> Doc) -> f -> Doc Source #
Version of blockMapF
that allows explicitly passing functions to format
key and value.
>>>
blockMapF' hexF build $ [(123, "foo"), (456, "bar")]
7b: foo 1c8: bar
blockListF :: (Buildable a, Foldable f) => f a -> Doc Source #
Render a list-like thing, YAML style.
>>>
blockListF ["foo", "bar", "baz"]
- foo - bar - baz>>>
blockListF ([] :: [Text])
[]
blockListF' :: Foldable f => Doc -> (a -> Doc) -> f a -> Doc Source #
Version of blockListF
that allows explicitly passing a bullet style and
formatter for items
>>>
blockListF' "*" hexF [1,11,21]
* 1 * b * 15
mapF :: (Buildable k, Buildable v, IsList f, Item f ~ (k, v)) => f -> Doc Source #
Format a map-like thing, JSON-style.
>>>
mapF [("foo", "bar"), ("baz", "quux")]
{foo: bar, baz: quux}>>>
mapF ([] :: [(Text, Text)])
{}>>>
mapF $ replicate 9 ("foo", "bar")
{ foo: bar , foo: bar ... , foo: bar }>>>
mapF $ [("foo", "bar\nquux"), ("baz", "corge")]
{ foo: bar quux , baz: corge }
mapF' :: (IsList f, Item f ~ (k, v)) => (k -> Doc) -> (v -> Doc) -> f -> Doc Source #
Version of mapF
allowing for custom formatters.
>>>
mapF' hexF build [(128, "foo"), (512, "bar")]
{80: foo, 200: bar}
listF :: (Buildable a, Foldable f) => f a -> Doc Source #
Print a list, JSON-style.
>>>
listF [1..3]
[1, 2, 3]>>>
listF [1..100]
[ 1 , 2 ... , 100 ]>>>
listF ["foo", "bar\nbaz"]
[ foo , bar baz ]
listF' :: Foldable f => (a -> Doc) -> f a -> Doc Source #
Version of listF
that allows explicitly specifying a formatter for items.
>>>
listF' hexF [1,11,21]
[1, b, 15]
whenF :: Bool -> Doc -> Doc Source #
Conditionally print something.
>>>
whenF True "foo"
foo>>>
show $ whenF False "foo"
""
unlessF :: Bool -> Doc -> Doc Source #
Boolean inverse of whenF
>>>
unlessF False "foo"
foo>>>
show $ unlessF True "foo"
""
enumerateF :: [(Text, Doc)] -> Doc Source #
Enumerate pairs of text and Doc
, reflowing the content to best-fit line
width. This will line-wrap text on whitespace. If Doc
is rendered single-line,
this will try to fit it inline. Otherwise, it's surrounded by newlines.
>>>
:{
long_text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. \ \ Donec eget diam ac lorem posuere dapibus in ut lorem. Morbi \ \ aliquet accumsan libero, a tempor nunc egestas ac." :}
>>>
enumerateF [(long_text, mempty)]
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec eget diam ac lorem posuere dapibus in ut lorem. Morbi aliquet accumsan libero, a tempor nunc egestas ac.
>>>
let splice = "SPLICE SPLICE SPLICE" :: Doc
>>>
:{
enumerateF [ (long_text, splice) , (long_text, mempty) ] :} Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec eget diam ac lorem posuere dapibus in ut lorem. Morbi aliquet accumsan libero, a tempor nunc egestas ac. SPLICE SPLICE SPLICE Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec eget diam ac lorem posuere dapibus in ut lorem. Morbi aliquet accumsan libero, a tempor nunc egestas ac.
>>>
let splice = build "SPLICE\nSPLICE\nSPLICE"
>>>
:{
enumerateF [ (long_text, splice) , ("Short text", mempty) ] :} Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec eget diam ac lorem posuere dapibus in ut lorem. Morbi aliquet accumsan libero, a tempor nunc egestas ac. SPLICE SPLICE SPLICE Short text
enumerateF' :: Doc -> [(Text, Doc)] -> Doc Source #
Version of enumerateF
that allows specifying separator between items.
>>>
enumerateF' "," [("Foo", build 1), ("bar", build 2), ("baz", build 3)]
Foo 1, bar 2, baz 3
whenNE :: Monoid a => a -> Doc -> a Source #
When the second argument is empty, return mempty
, otherwise, return the
first argument.
fillSepF :: (Foldable t, Buildable a) => t a -> Doc Source #
Like fillSep
, but skips over empty elements.
fillSepF' :: (Foldable t, Buildable a) => Doc -> t a -> Doc Source #
Version of fillSepF
with punctuation.
reflowF :: Text -> Doc Source #
Reflow text, line-wrapping on white-space. Any leading and trailing whitespace is stripped.
singleLineF :: Buildable a => a -> Doc Source #
Force the Doc
to be rendered on a single line, regardless of anything,
including hard line breaks. Will lead to horrible terrible formatting if
overused. In all likelihood, this is not the function you're looking for.
Note that hard line breaks will be removed entirely, not replaced with spaces.
>>>
singleLineF ("foo\nbar\nbaz" :: Text)
foobarbaz
:: (Foldable t, Buildable a) | |
=> Doc | Default separator, usually comma |
-> Doc | Pair separator, usually |
-> t a | Foldable to punctuate |
-> [Doc] |
Punctuate a foldable with a distinct separator for the last two elements. Useful for enumerations. Does the oxford comma by concatenating first and second arguments. Note that when using a word, a leading space is expected on the pair separator.
>>>
fillSepF $ punctuateF "," " and" ([] :: [Doc])
>>>
fillSepF $ punctuateF "," " and" ["foo"]
foo>>>
fillSepF $ punctuateF "," " and" ["bar", "baz"]
bar and baz>>>
fillSepF $ punctuateF "," " and" ["foo", "bar", "baz"]
foo, bar, and baz
:: (Foldable t, Buildable a) | |
=> Doc | Default separator |
-> Doc | Pair separator |
-> Doc | Penultimate element separator |
-> t a | |
-> [Doc] |
Version of punctuateF
with explicit distinct separators for penultimate
element and just two elements.
>>>
fillSepF $ punctuateF' "," " and" ", and" ([] :: [Doc])
>>>
fillSepF $ punctuateF' "," " and" ", and" ["foo"]
foo>>>
fillSepF $ punctuateF' "," " and" ", and" ["bar", "baz"]
bar and baz>>>
fillSepF $ punctuateF' "," " and" ", and" ["foo", "bar", "baz"]
foo, bar, and baz
quoteF' :: Buildable a => Doc -> Doc -> a -> Doc Source #
Surround a Buildable
with quotes (or anything else really).
quoteF' l r x
is equivalent to l <> build x <> r
, but it may be more
convenient in some cases.
>>>
quoteF' "\"" "\"" "Foo"
"Foo"
quoteOrIndentF :: Buildable a => a -> Doc Source #
If buildable fits into the line, wrap it in single quotes. Otherwise,
indent it by 2 spaces. This is convenient with enumerateF
or reflowing
brackets to format a splice that can be long and multiline or short and
singleline with about equal probability.
This is a particularly useful specialization of flatAltF
.
>>>
let splice = "lorem posuere dapibus" :: Doc
>>>
let long_splice = unwordsF $ replicate 3 splice
>>>
let very_long_splice = unwordsF $ replicate 4 splice
>>>
"Foobar" ++| quoteOrIndentF splice |++ "bazbar."
Foobar 'lorem posuere dapibus' bazbar.
>>>
"Foobarbazquux" ++| quoteOrIndentF long_splice |++ "bazbar."
Foobarbazquux 'lorem posuere dapibus lorem posuere dapibus lorem posuere dapibus' bazbar.
>>>
"Foobarbazquux" ++| quoteOrIndentF long_splice |++^ "bazbar."
Foobarbazquux lorem posuere dapibus lorem posuere dapibus lorem posuere dapibus bazbar.
>>>
"Foobar" ++| quoteOrIndentF very_long_splice |++ "bazbar."
Foobar lorem posuere dapibus lorem posuere dapibus lorem posuere dapibus lorem posuere dapibus bazbar.
>>>
"Foobar" ++| quoteOrIndentF very_long_splice |++^ "bazbar."
Foobar lorem posuere dapibus lorem posuere dapibus lorem posuere dapibus lorem posuere dapibus bazbar.
Use different formatters depending on whether the pretty-printed
representation fits on the current line or not. The exact meaning of "fits" is
determined by the surrounding context. In precise terms, whether multiline or
single-line format is chosen is determined by whether the enclosing group
is
broken or not, respectively. Useful with reflowing brackets, nameF
, etc to
specify alternate format for short andor single-line and long andor multiline
text.
>>>
let short = "bar baz" :: Text
>>>
let long = unwordsF $ replicate 10 short
>>>
nameF "Foo" $ flatAltF (quoteF "\"") (quoteF "'") short
Foo: 'bar baz'
>>>
nameF "Foo" $ flatAltF (quoteF "\"") (quoteF "'") long
Foo: "bar baz bar baz bar baz bar baz bar baz bar baz bar baz bar baz bar baz bar baz"
Class for formatting tuples
>>>
tupleF ("foo", "bar", "baz")
(foo, bar, baz)>>>
tupleF ("foo","bar\nbaz")
( foo , bar baz )>>>
:{
tupleF ( "foo", "foo", "foo", "foo", "foo" , "foo", "foo", "foo", "foo", "foo" , "foo", "foo", "foo", "foo", "foo" , "foo", "foo", "foo", "foo", "foo" ) :} ( foo , foo ... , foo )
Instances
Buildable a => TupleF [a] Source # | |
Defined in Fmt.Buildable | |
(Buildable a1, Buildable a2) => TupleF (a1, a2) Source # | |
Defined in Fmt.Buildable | |
(Buildable a1, Buildable a2, Buildable a3) => TupleF (a1, a2, a3) Source # | |
Defined in Fmt.Buildable | |
(Buildable a1, Buildable a2, Buildable a3, Buildable a4) => TupleF (a1, a2, a3, a4) Source # | |
Defined in Fmt.Buildable | |
(Buildable a1, Buildable a2, Buildable a3, Buildable a4, Buildable a5) => TupleF (a1, a2, a3, a4, a5) Source # | |
Defined in Fmt.Buildable | |
(Buildable a1, Buildable a2, Buildable a3, Buildable a4, Buildable a5, Buildable a6) => TupleF (a1, a2, a3, a4, a5, a6) Source # | |
Defined in Fmt.Buildable | |
(Buildable a1, Buildable a2, Buildable a3, Buildable a4, Buildable a5, Buildable a6, Buildable a7) => TupleF (a1, a2, a3, a4, a5, a6, a7) Source # | |
Defined in Fmt.Buildable | |
(Buildable a1, Buildable a2, Buildable a3, Buildable a4, Buildable a5, Buildable a6, Buildable a7, Buildable a8) => TupleF (a1, a2, a3, a4, a5, a6, a7, a8) Source # | |
Defined in Fmt.Buildable | |
(Buildable a1, Buildable a2, Buildable a3, Buildable a4, Buildable a5, Buildable a6, Buildable a7, Buildable a8, Buildable a9) => TupleF (a1, a2, a3, a4, a5, a6, a7, a8, a9) Source # | |
Defined in Fmt.Buildable | |
(Buildable a1, Buildable a2, Buildable a3, Buildable a4, Buildable a5, Buildable a6, Buildable a7, Buildable a8, Buildable a9, Buildable a10) => TupleF (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) Source # | |
Defined in Fmt.Buildable | |
(Buildable a1, Buildable a2, Buildable a3, Buildable a4, Buildable a5, Buildable a6, Buildable a7, Buildable a8, Buildable a9, Buildable a10, Buildable a11) => TupleF (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11) Source # | |
Defined in Fmt.Buildable | |
(Buildable a1, Buildable a2, Buildable a3, Buildable a4, Buildable a5, Buildable a6, Buildable a7, Buildable a8, Buildable a9, Buildable a10, Buildable a11, Buildable a12) => TupleF (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12) Source # | |
Defined in Fmt.Buildable | |
(Buildable a1, Buildable a2, Buildable a3, Buildable a4, Buildable a5, Buildable a6, Buildable a7, Buildable a8, Buildable a9, Buildable a10, Buildable a11, Buildable a12, Buildable a13) => TupleF (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13) Source # | |
Defined in Fmt.Buildable | |
(Buildable a1, Buildable a2, Buildable a3, Buildable a4, Buildable a5, Buildable a6, Buildable a7, Buildable a8, Buildable a9, Buildable a10, Buildable a11, Buildable a12, Buildable a13, Buildable a14) => TupleF (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14) Source # | |
Defined in Fmt.Buildable | |
(Buildable a1, Buildable a2, Buildable a3, Buildable a4, Buildable a5, Buildable a6, Buildable a7, Buildable a8, Buildable a9, Buildable a10, Buildable a11, Buildable a12, Buildable a13, Buildable a14, Buildable a15) => TupleF (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15) Source # | |
Defined in Fmt.Buildable | |
(Buildable a1, Buildable a2, Buildable a3, Buildable a4, Buildable a5, Buildable a6, Buildable a7, Buildable a8, Buildable a9, Buildable a10, Buildable a11, Buildable a12, Buildable a13, Buildable a14, Buildable a15, Buildable a16) => TupleF (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16) Source # | |
Defined in Fmt.Buildable | |
(Buildable a1, Buildable a2, Buildable a3, Buildable a4, Buildable a5, Buildable a6, Buildable a7, Buildable a8, Buildable a9, Buildable a10, Buildable a11, Buildable a12, Buildable a13, Buildable a14, Buildable a15, Buildable a16, Buildable a17) => TupleF (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17) Source # | |
Defined in Fmt.Buildable | |
(Buildable a1, Buildable a2, Buildable a3, Buildable a4, Buildable a5, Buildable a6, Buildable a7, Buildable a8, Buildable a9, Buildable a10, Buildable a11, Buildable a12, Buildable a13, Buildable a14, Buildable a15, Buildable a16, Buildable a17, Buildable a18) => TupleF (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18) Source # | |
Defined in Fmt.Buildable | |
(Buildable a1, Buildable a2, Buildable a3, Buildable a4, Buildable a5, Buildable a6, Buildable a7, Buildable a8, Buildable a9, Buildable a10, Buildable a11, Buildable a12, Buildable a13, Buildable a14, Buildable a15, Buildable a16, Buildable a17, Buildable a18, Buildable a19) => TupleF (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19) Source # | |
Defined in Fmt.Buildable | |
(Buildable a1, Buildable a2, Buildable a3, Buildable a4, Buildable a5, Buildable a6, Buildable a7, Buildable a8, Buildable a9, Buildable a10, Buildable a11, Buildable a12, Buildable a13, Buildable a14, Buildable a15, Buildable a16, Buildable a17, Buildable a18, Buildable a19, Buildable a20) => TupleF (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20) Source # | |
Defined in Fmt.Buildable | |
(Buildable a1, Buildable a2, Buildable a3, Buildable a4, Buildable a5, Buildable a6, Buildable a7, Buildable a8, Buildable a9, Buildable a10, Buildable a11, Buildable a12, Buildable a13, Buildable a14, Buildable a15, Buildable a16, Buildable a17, Buildable a18, Buildable a19, Buildable a20, Buildable a21) => TupleF (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21) Source # | |
Defined in Fmt.Buildable | |
(Buildable a1, Buildable a2, Buildable a3, Buildable a4, Buildable a5, Buildable a6, Buildable a7, Buildable a8, Buildable a9, Buildable a10, Buildable a11, Buildable a12, Buildable a13, Buildable a14, Buildable a15, Buildable a16, Buildable a17, Buildable a18, Buildable a19, Buildable a20, Buildable a21, Buildable a22) => TupleF (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22) Source # | |
Defined in Fmt.Buildable | |
(Buildable a1, Buildable a2, Buildable a3, Buildable a4, Buildable a5, Buildable a6, Buildable a7, Buildable a8, Buildable a9, Buildable a10, Buildable a11, Buildable a12, Buildable a13, Buildable a14, Buildable a15, Buildable a16, Buildable a17, Buildable a18, Buildable a19, Buildable a20, Buildable a21, Buildable a22, Buildable a23) => TupleF (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22, a23) Source # | |
Defined in Fmt.Buildable | |
(Buildable a1, Buildable a2, Buildable a3, Buildable a4, Buildable a5, Buildable a6, Buildable a7, Buildable a8, Buildable a9, Buildable a10, Buildable a11, Buildable a12, Buildable a13, Buildable a14, Buildable a15, Buildable a16, Buildable a17, Buildable a18, Buildable a19, Buildable a20, Buildable a21, Buildable a22, Buildable a23, Buildable a24) => TupleF (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22, a23, a24) Source # | |
Defined in Fmt.Buildable | |
(Buildable a1, Buildable a2, Buildable a3, Buildable a4, Buildable a5, Buildable a6, Buildable a7, Buildable a8, Buildable a9, Buildable a10, Buildable a11, Buildable a12, Buildable a13, Buildable a14, Buildable a15, Buildable a16, Buildable a17, Buildable a18, Buildable a19, Buildable a20, Buildable a21, Buildable a22, Buildable a23, Buildable a24, Buildable a25) => TupleF (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22, a23, a24, a25) Source # | |
Defined in Fmt.Buildable | |
(Buildable a1, Buildable a2, Buildable a3, Buildable a4, Buildable a5, Buildable a6, Buildable a7, Buildable a8, Buildable a9, Buildable a10, Buildable a11, Buildable a12, Buildable a13, Buildable a14, Buildable a15, Buildable a16, Buildable a17, Buildable a18, Buildable a19, Buildable a20, Buildable a21, Buildable a22, Buildable a23, Buildable a24, Buildable a25, Buildable a26) => TupleF (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22, a23, a24, a25, a26) Source # | |
Defined in Fmt.Buildable | |
(Buildable a1, Buildable a2, Buildable a3, Buildable a4, Buildable a5, Buildable a6, Buildable a7, Buildable a8, Buildable a9, Buildable a10, Buildable a11, Buildable a12, Buildable a13, Buildable a14, Buildable a15, Buildable a16, Buildable a17, Buildable a18, Buildable a19, Buildable a20, Buildable a21, Buildable a22, Buildable a23, Buildable a24, Buildable a25, Buildable a26, Buildable a27) => TupleF (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22, a23, a24, a25, a26, a27) Source # | |
Defined in Fmt.Buildable | |
(Buildable a1, Buildable a2, Buildable a3, Buildable a4, Buildable a5, Buildable a6, Buildable a7, Buildable a8, Buildable a9, Buildable a10, Buildable a11, Buildable a12, Buildable a13, Buildable a14, Buildable a15, Buildable a16, Buildable a17, Buildable a18, Buildable a19, Buildable a20, Buildable a21, Buildable a22, Buildable a23, Buildable a24, Buildable a25, Buildable a26, Buildable a27, Buildable a28) => TupleF (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22, a23, a24, a25, a26, a27, a28) Source # | |
Defined in Fmt.Buildable | |
(Buildable a1, Buildable a2, Buildable a3, Buildable a4, Buildable a5, Buildable a6, Buildable a7, Buildable a8, Buildable a9, Buildable a10, Buildable a11, Buildable a12, Buildable a13, Buildable a14, Buildable a15, Buildable a16, Buildable a17, Buildable a18, Buildable a19, Buildable a20, Buildable a21, Buildable a22, Buildable a23, Buildable a24, Buildable a25, Buildable a26, Buildable a27, Buildable a28, Buildable a29) => TupleF (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22, a23, a24, a25, a26, a27, a28, a29) Source # | |
Defined in Fmt.Buildable | |
(Buildable a1, Buildable a2, Buildable a3, Buildable a4, Buildable a5, Buildable a6, Buildable a7, Buildable a8, Buildable a9, Buildable a10, Buildable a11, Buildable a12, Buildable a13, Buildable a14, Buildable a15, Buildable a16, Buildable a17, Buildable a18, Buildable a19, Buildable a20, Buildable a21, Buildable a22, Buildable a23, Buildable a24, Buildable a25, Buildable a26, Buildable a27, Buildable a28, Buildable a29, Buildable a30) => TupleF (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22, a23, a24, a25, a26, a27, a28, a29, a30) Source # | |
Defined in Fmt.Buildable |
hexF
class FormatAsHex a where Source #
Format a number or bytestring as hex:
>>>
pretty $ hexF 3635
e33>>>
pretty $ hexF (-3635)
-e33>>>
pretty $ hexF ("\0\50\63\80" :: ByteString)
00323f50>>>
pretty $ hexF ("\0\50\63\80" :: LByteString)
00323f50
Instances
FormatAsHex Int16 Source # | |
FormatAsHex Int32 Source # | |
FormatAsHex Int64 Source # | |
FormatAsHex Int8 Source # | |
FormatAsHex Word16 Source # | |
FormatAsHex Word32 Source # | |
FormatAsHex Word64 Source # | |
FormatAsHex Word8 Source # | |
FormatAsHex ByteString Source # | |
Defined in Fmt.Buildable hexF :: ByteString -> Doc Source # | |
FormatAsHex LByteString Source # | |
Defined in Fmt.Buildable hexF :: LByteString -> Doc Source # | |
FormatAsHex Integer Source # | |
FormatAsHex Natural Source # | |
FormatAsHex Int Source # | |
FormatAsHex Word Source # | |
Integral a => FormatAsHex (Hex a) Source # | |
Wrap an integral type with this if there's no FormatAsHex
instance for it
yet, or use it with DerivingVia
.
>>>
hexF $ Hex 128
80
Hex a |
Generics
newtype GenericBuildable a Source #
Newtype for use with DerivingVia
, e.g.
>>>
:{
data Foo = Bar | Baz deriving (Generic, Buildable) :}
>>>
build Bar
Bar
Handles infix constructors properly:
>>>
data Inf = Text :-> Text deriving (Generic, Buildable)
>>>
build $ "foo" :-> "bar"
foo :-> bar>>>
data Inf2 = Text `Con` Text deriving (Generic, Buildable)
>>>
build $ Con "foo" "bar"
foo `Con` bar
>>>
:{
data LargeTy = LargeTy Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text deriving (Generic, Buildable) :}
>>>
:{
build $ LargeTy "foo" "foo" "foo" "foo" "foo" "foo" "foo" "foo" "foo" "foo" "foo" "foo" "foo" "foo" "foo" "foo" "foo" "foo" "foo" "foo" :} LargeTy; foo, foo, foo, foo, foo, foo, foo, foo, foo, foo, foo, foo, foo, foo, foo, foo, foo, foo, foo, foo
There is a special case for tuples:
>>>
:{
newtype Tup = Tup (Int, Int, Text) deriving stock Generic deriving anyclass Buildable :}
>>>
build $ Tup (1, 2, "many")
Tup; (1, 2, many)>>>
build $ Tup (1, 2, "many\nlines")
Tup; ( 1 , 2 , many lines )
Renders records as maps
>>>
:{
data Rec = Rec { foo :: Text , bar :: Text , baz :: Text } deriving (Generic, Buildable) :}
>>>
build $ Rec "quux" "waldo" "corge"
Rec: foo: quux bar: waldo baz: corge
Instances
(GBuildable (Rep a), Generic a) => Buildable (GenericBuildable a) Source # | |
Defined in Fmt.Buildable build :: GenericBuildable a -> Doc Source # buildList :: [GenericBuildable a] -> Doc Source # |
class GBuildable f where Source #
Instances
Buildable c => GBuildable (Rec0 c :: k -> Type) Source # | |
(GBuildable a, GBuildable b) => GBuildable (a :+: b :: k -> Type) Source # | |
(GetFields a, Constructor c) => GBuildable (C1 c a :: k -> Type) Source # | |
GBuildable a => GBuildable (D1 d a :: k -> Type) Source # | |