formatting-7.2.0: Combinator-based type-safe formatting (like printf() or FORMAT)

Safe Haskell | Safe-Inferred
Language | Haskell2010

Formatting.FromBuilder

Synopsis

- class FromBuilder a where
  - fromBuilder :: Builder -> a
- formatted :: FromBuilder t => (t -> o) -> Format o a -> a

# Documentation

class FromBuilder a where Source #

Anything that can be created from a `Builder`. This class makes it easier to add formatting to other API's. See `formatted` for some examples of this class in action.

Methods

fromBuilder :: Builder -> a Source #

#### Instances

Instances details

FromBuilder Text Source # |
Instance details Defined in Formatting.FromBuilder Methods fromBuilder :: Builder -> Text Source #
FromBuilder Builder Source # |
Instance details Defined in Formatting.FromBuilder Methods fromBuilder :: Builder -> Builder Source #
FromBuilder Text Source # |
Instance details Defined in Formatting.FromBuilder Methods fromBuilder :: Builder -> Text Source #
FromBuilder [Char] Source # |
Instance details Defined in Formatting.FromBuilder Methods fromBuilder :: Builder -> [Char] Source #

formatted :: FromBuilder t => (t -> o) -> Format o a -> a Source #

Makes it easy to add formatting to any api that is expecting a builder, a strict or lazy text, or a string. It is essentially (flip runFormat), but with a more generous type due to the typeclass.

For example: >>> formatted TL.putStr ("x is: " % int % "n") 7 x is: 7 >>> formatted T.putStr ("x is: " % int % "n") 7 x is: 7 >>> formatted (id `TL.Text) ("x is: " % int % "n") 7 "x is: 7n" >>> formatted (id` T.Text) ("x is: " % int % "n") 7 "x is: 7n"