serokell-util-0.5.0: General-purpose functions by Serokell

Safe HaskellNone
LanguageHaskell2010

Serokell.Util.Text

Contents

Description

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

formatting utilities

show :: Buildable a => a -> Text Source #

show' :: Buildable a => a -> Text Source #

data FPFormat :: * #

Control the rendering of floating point numbers.

Constructors

Exponent

Scientific notation (e.g. 2.3e123).

Fixed

Standard decimal notation.

Generic

Use decimal notation for values between 0.1 and 9,999,999, and scientific notation otherwise.

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.

Formatters

pairF :: (Buildable a, Buildable b) => Format r ((a, b) -> r) Source #

tripleF :: (Buildable a, Buildable b, Buildable c) => Format r ((a, b, c) -> r) Source #

listJson :: (Foldable t, Buildable a) => Format r (t a -> r) Source #

listJsonIndent :: (Foldable t, Buildable a) => Word -> Format r (t a -> r) Source #

listCsv :: (Foldable t, Buildable a) => Format r (t a -> r) Source #

mapJson :: (IsList t, Item t ~ (k, v), Buildable k, Buildable v) => Format r (t -> r) Source #

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

listBuilderCSV :: (Foldable t, Buildable a) => t a -> Builder Source #

Prints comma separated values

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.

mapBuilderJson :: (IsList t, Item t ~ (k, v), Buildable k, Buildable v) => t -> Builder Source #

text-format utilities

format :: Params ps => Format -> ps -> Text Source #

Deprecated: Not typesafe. Use formatting library instead

Re-export Data.Text.Format.format for convenience

format' :: Params ps => Format -> ps -> Text Source #

Deprecated: Not typesafe. Use formatting library instead

Version of Data.Text.Format.format which returns strict Text

formatSingle :: Buildable a => Format -> a -> Text Source #

Deprecated: Not typesafe. Use formatting library instead

formatSingle' :: Buildable a => Format -> a -> Text Source #

Deprecated: Not typesafe. Use formatting library instead

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

readDecimal :: Integral a => Text -> Either String a Source #

Read signed decimal number. Returns error (i. e. Left) if there is something else WARNING: if input is negative and a is unsigned, overflow will occur

readUnsignedDecimal :: Integral a => Text -> Either String a Source #

Read unsigned decimal number. Returns error (i. e. Left) if there is something else