stringfmt
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.Fmt.ByteString

Description

ByteString formatting via Builder.

Synopsis

ByteFmt

type ByteFmt = Fmt Builder Source #

A Fmt specialized to Builder.

runByteFmt :: ByteFmt ByteString a -> a Source #

Run a ByteFmt to produce a lazy ByteString.

printf :: ByteFmt (IO ()) a -> a Source #

Run a ByteFmt and print the result to stdout.

Combinators

cat1With :: Foldable f => ([ByteString] -> ByteString) -> Fmt1 Builder ByteString a -> Fmt1 Builder s (f a) Source #

Format each value in a foldable and join the results.

hsep :: Foldable f => Fmt1 Builder ByteString a -> Fmt1 Builder s (f a) Source #

Format each value with spaces in between.

>>> runByteFmt (hsep (fmt1 byteString)) ["one", "two", "three"]
"one two three"

vsep :: Foldable f => Fmt1 Builder ByteString a -> Fmt1 Builder s (f a) Source #

Format each value on its own line.

hang :: Foldable f => Int -> Fmt1 Builder ByteString a -> Fmt1 Builder s (f a) Source #

Format each value on its own line, indented by n spaces.

list1 :: Foldable f => Fmt1 Builder ByteString a -> Fmt1 Builder s (f a) Source #

Format in square brackets with comma separation.

>>> runByteFmt (list1 (fmt1 byteString)) ["one", "two"]
"[one, two]"

Splitting

replace1 :: ByteString -> Fmt Builder a a -> Fmt Builder a b -> Fmt Builder a b Source #

Replace the first occurrence of a search term.

>>> runByteFmt (replace1 "bar" "FOO" (fmt (byteString "foobarbaz")))
"fooFOObaz"

splitWith :: (ByteString -> (ByteString, ByteString)) -> (ByteString -> ByteString -> Fmt Builder a2 a1) -> Fmt Builder a1 b -> Fmt Builder a2 b Source #

Split the formatted output using a splitting function, then rejoin with a custom combinator.

Running Fmt1

run1 :: Fmt1 Builder ByteString a -> a -> ByteString Source #

Run a Fmt1 to strict ByteString.

Structured output

jsonList :: Foldable f => Fmt1 Builder ByteString a -> Fmt1 Builder s (f a) Source #

Format a foldable as a JSON-style list.

>>> printf (jsonList (fmt1 byteString)) ["one", "two"]
["one", "two"]

yamlList :: Foldable f => Fmt1 Builder ByteString a -> Fmt1 Builder s (f a) Source #

Format a foldable as a YAML-style list.

>>> printf (yamlList (fmt1 byteString)) ["one", "two"]
- one
- two

jsonMap :: Foldable f => Fmt1 Builder ByteString k -> Fmt1 Builder ByteString v -> Fmt1 Builder s (f (k, v)) Source #

Format key-value pairs as a JSON-style map.

yamlMap :: Foldable f => Fmt1 Builder ByteString k -> Fmt1 Builder ByteString v -> Fmt1 Builder s (f (k, v)) Source #

Format key-value pairs as a YAML-style map.