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.
:: a typeCtrl KGHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05
Modulefmt-0.6.3.0Haskell2010
import FmtIndent 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.
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.
Attach a name to anything:
fmt $ nameF "clients" $ blockListF ["Alice", "Bob", "Zalgo"]clients: - Alice - Bob - Zalgo
Put spaces between elements.
fmt $ unwordsF ["hello", "world"]hello world
Of course, it works on anything Buildable:
fmt $ unwordsF [1, 2]1 2
Arrange elements on separate lines.
fmt $ unlinesF ["hello", "world"]helloworld
A simple comma-separated list formatter.
listF ["hello", "world"]"[hello, world]"
For multiline output, use jsonListF.
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:
listF' hexF [1234, 5678]"[4d2, 162e]"
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' 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 "-").
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]
A version of jsonListF that lets you supply your own building function for list elements.
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.
A version of mapF that lets you supply your own building function for keys and values.
A YAML-like map formatter:
fmt $ blockMapF [("Odds", blockListF [1,3]), ("Evens", blockListF [2,4])]Odds: - 1 - 3Evens: - 2 - 4
A version of blockMapF that lets you supply your own building function for keys and values.
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 ]}
A version of jsonMapF that lets you supply your own building function for keys and values.
Format an Either:
eitherF (Right 1 :: Either Bool Int)"<Right: 1>"
Take the first N characters:
prefixF 3 "hello""hel"
Take the last N characters:
suffixF 3 "hello""llo"
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"
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"
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=="
Display something only if the condition is False (empty string otherwise).