HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulefmt-0.6.3.0Haskell2010

Fmt.Internal.Formatters

  • 26 values
  • Packagefmt-0.6.3.0
  • Exports26
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceFormatters.hs
Example1 expression
import Fmt
valueindentF :: Int -> Builder -> Builder
#

Indent a block of text.

Example1 expression
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.

valueindentF' :: Int -> Text -> 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.

valuenameF :: Builder -> Builder -> Builder
#

Attach a name to anything:

Example1 expression
fmt $ nameF "clients" $ blockListF ["Alice", "Bob", "Zalgo"]clients:  - Alice  - Bob  - Zalgo
valueunwordsF :: (Foldable f, Buildable a) => f a -> Builder
#

Put spaces between elements.

Example1 expression
fmt $ unwordsF ["hello", "world"]hello world

Of course, it works on anything Buildable:

Example1 expression
fmt $ unwordsF [1, 2]1 2
valueunlinesF :: (Foldable f, Buildable a) => f a -> Builder
#

Arrange elements on separate lines.

Example1 expression
fmt $ unlinesF ["hello", "world"]helloworld
valuelistF :: (Foldable f, Buildable a) => f a -> Builder
#

A simple comma-separated list formatter.

Example1 expression
listF ["hello", "world"]"[hello, world]"

For multiline output, use jsonListF.

valuelistF' :: Foldable f => (a -> Builder) -> 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 numbers as hex:

Example1 expression
listF' hexF [1234, 5678]"[4d2, 162e]"
valueblockListF :: (Foldable f, Buildable a) => f a -> Builder
#

A multiline formatter for lists.

Example1 expression
fmt $ blockListF [1,2,3]- 1- 2- 3

Multi-line elements are indented correctly:

Example1 expression
fmt $ blockListF ["hello\nworld", "foo\nbar\nquix"]- hello  world- foo  bar  quix
valueblockListF'
  1. :: Foldable f
  2. => Text

    Bullet

  3. -> (a -> Builder)

    Builder for elements

  4. -> f a

    Structure with elements

  5. -> 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 "-").

valuejsonListF :: (Foldable f, Buildable a) => f a -> Builder
#

A JSON-style formatter for lists.

Example1 expression
fmt $ jsonListF [1,2,3][  1, 2, 3]

Like blockListF, it handles multiline elements well:

Example1 expression
fmt $ jsonListF ["hello\nworld", "foo\nbar\nquix"][  hello  world, foo  bar  quix]
valuemapF
  1. :: (IsList t, Item t ~ (k, v), Buildable k, Buildable v)
  2. => t
  3. -> Builder
#

A simple JSON-like map formatter; works for Map, HashMap, etc, as well as ordinary lists of pairs.

Example1 expression
mapF [("a", 1), ("b", 4)]"{a: 1, b: 4}"

For multiline output, use jsonMapF.

valueblockMapF
  1. :: (IsList t, Item t ~ (k, v), Buildable k, Buildable v)
  2. => t
  3. -> Builder
#

A YAML-like map formatter:

Example1 expression
fmt $ blockMapF [("Odds", blockListF [1,3]), ("Evens", blockListF [2,4])]Odds:  - 1  - 3Evens:  - 2  - 4
valuejsonMapF
  1. :: (IsList t, Item t ~ (k, v), Buildable k, Buildable v)
  2. => t
  3. -> Builder
#

A JSON-like map formatter (unlike mapF, always multiline):

Example1 expression
fmt $ jsonMapF [("Odds", jsonListF [1,3]), ("Evens", jsonListF [2,4])]{  Odds:    [      1    , 3    ], Evens:    [      2    , 4    ]}
valuemaybeF :: Buildable a => Maybe a -> Builder
#

Like build for Maybe, but displays Nothing as <Nothing> instead of an empty string.

build:

Example2 expressions
build (Nothing :: Maybe Int)""build (Just 1 :: Maybe Int)"1"

maybeF:

Example2 expressions
maybeF (Nothing :: Maybe Int)"<Nothing>"maybeF (Just 1 :: Maybe Int)"1"
valuepadLeftF :: Buildable a => Int -> Char -> 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):

Example2 expressions
padLeftF 5 '0' 12"00012"padLeftF 5 '0' 123456"123456"
valuepadRightF :: 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):

Example2 expressions
padRightF 5 ' ' "foo""foo  "padRightF 5 ' ' "foobar""foobar"
valuepadBothF :: 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):

Example2 expressions
padBothF 5 '=' "foo""=foo="padBothF 5 '=' "foobar""foobar"

When padding can't be distributed equally, the left side is preferred:

Example1 expression
padBothF 8 '=' "foo""===foo=="
valuewhenF :: Bool -> Builder -> 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.