stringfmt
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.Fmt.String

Description

String formatting via ShowS-backed Builder.

import Data.Fmt
import Data.Fmt.String

runStringFmt $ "hello" % " " % "world"
-- "hello world"
Synopsis

Builder

newtype Builder Source #

A ShowS-backed string builder with O(1) concatenation.

Constructors

Builder 

Fields

Instances

Instances details
IsString Builder Source # 
Instance details

Defined in Data.Fmt.String

Methods

fromString :: String -> Builder #

Monoid Builder Source # 
Instance details

Defined in Data.Fmt.String

Semigroup Builder Source # 
Instance details

Defined in Data.Fmt.String

Show Builder Source # 
Instance details

Defined in Data.Fmt.String

StringFmt

type StringFmt = Fmt Builder Source #

A Fmt specialized to Builder.

runStringFmt :: StringFmt String a -> a Source #

Run a StringFmt to produce a String.

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

Run a StringFmt and print the result to stdout.

Combinators

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

Format each value in a foldable and join the results.

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

Format each value with spaces in between.

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

Format each value on its own line.

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

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

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

Format in square brackets with comma separation.

Splitting

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

Replace the first occurrence of a search term.

splitWith :: (String -> (String, String)) -> (String -> String -> 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 String a -> a -> String Source #

Run a Fmt1 to String.

Structured output

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

Format a foldable as a JSON-style list.

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

Format a foldable as a YAML-style list.

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

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

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

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