Safe Haskell | None |
---|---|
Language | Haskell2010 |
Utility functions to work with text
and `text-format`. Feel
free to add more if you need. Some functions have two versions, `'`
suffix means that function operates on strict Text.
Synopsis
- data FPFormat
- showFloat :: RealFloat a => FPFormat -> Maybe Int -> a -> Text
- showFloat' :: RealFloat a => FPFormat -> Maybe Int -> a -> Text
- showFixedPretty' :: Real a => Int -> a -> Text
- showDecimal :: Integral a => a -> Text
- showDecimal' :: Integral a => a -> Text
- pairF :: (Buildable a, Buildable b) => Format r ((a, b) -> r)
- tripleF :: (Buildable a, Buildable b, Buildable c) => Format r ((a, b, c) -> r)
- listJson :: (Foldable t, Buildable a) => Format r (t a -> r)
- listMap :: (Traversable t, Buildable a, Buildable b) => Format r (t (a, b) -> r)
- listJsonIndent :: (Foldable t, Buildable a) => Word -> Format r (t a -> r)
- listChunkedJson :: (Container l, Buildable (Element l)) => Int -> Format r (l -> r)
- listCsv :: (Foldable t, Buildable a) => Format r (t a -> r)
- mapJson :: (IsList t, Item t ~ (k, v), Buildable k, Buildable v) => Format r (t -> r)
- pairBuilder :: (Buildable a, Buildable b) => (a, b) -> Builder
- tripleBuilder :: (Buildable a, Buildable b, Buildable c) => (a, b, c) -> Builder
- listBuilder :: (Buildable prefix, Buildable delimiter, Buildable suffix, Foldable t, Buildable a) => prefix -> delimiter -> suffix -> t a -> Builder
- listBuilderJSON :: (Foldable t, Buildable a) => t a -> Builder
- listBuilderJSONIndent :: (Foldable t, Buildable a) => Word -> t a -> Builder
- listChunkedBuilderJson :: (Container l, Buildable (Element l)) => Int -> l -> Builder
- listBuilderCSV :: (Foldable t, Buildable a) => t a -> Builder
- mapBuilder :: (Traversable t, Buildable k, Buildable v) => t (k, v) -> Builder
- mapBuilderJson :: (IsList t, Item t ~ (k, v), Buildable k, Buildable v) => t -> Builder
- readFractional :: Fractional a => Text -> Either String a
- readDouble :: Text -> Either String Double
- readDecimal :: Integral a => Text -> Either String a
- readUnsignedDecimal :: Integral a => Text -> Either String a
formatting
utilities
Control the rendering of floating point numbers.
Exponent | Scientific notation (e.g. |
Fixed | Standard decimal notation. |
Generic | Use decimal notation for values between |
Instances
Enum FPFormat | |
Defined in Data.Text.Lazy.Builder.RealFloat | |
Read FPFormat | |
Show FPFormat | |
showFixedPretty' :: Real a => Int -> a -> Text Source #
Render a floating point number using normal notation, with the given number of decimal places. This function also truncates redundant terminating zeros.
showDecimal :: Integral a => a -> Text Source #
showDecimal' :: Integral a => a -> Text Source #
Formatters
Builders
pairBuilder :: (Buildable a, Buildable b) => (a, b) -> Builder Source #
Prints pair (a, b) like "(a, b)"
tripleBuilder :: (Buildable a, Buildable b, Buildable c) => (a, b, c) -> Builder Source #
Prints triple (a, b, c) like "(a, b, c)"
listBuilder :: (Buildable prefix, Buildable delimiter, Buildable suffix, Foldable t, Buildable a) => prefix -> delimiter -> suffix -> t a -> Builder Source #
Generic list builder. Prints prefix, then values separated by delimiter and finally suffix
listBuilderJSON :: (Foldable t, Buildable a) => t a -> Builder Source #
Prints values in JSON-style (e. g. `[111, ololo, blablabla]`)
listBuilderJSONIndent :: (Foldable t, Buildable a) => Word -> t a -> Builder Source #
Like listBuilderJSON, but prints each value on a new line with indentation
listChunkedBuilderJson :: (Container l, Buildable (Element l)) => Int -> l -> Builder Source #
Like listBuilderJSON. but prints per chunkSize
elements on a line.
mapBuilder :: (Traversable t, Buildable k, Buildable v) => t (k, v) -> Builder Source #
There is no appropriate type class for map, but all reasonable maps
provide something like assocs
function.
Map may be printed prettier (e. g. using JSON style), it's future task.
Having at least one such function is still good anyway.
String readers
readFractional :: Fractional a => Text -> Either String a Source #
Read fractional number. Returns error (i. e. Left) if there is something else
readDouble :: Text -> Either String Double Source #
Like readFractional, but much more efficient. It may be slightly less accurate