packages feed

fmt 0.6 → 0.6.1

raw patch · 6 files changed

+56/−9 lines, 6 filesdep ~basePVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependency ranges changed: base

API changes (from Hackage documentation)

- Fmt.Internal.Core: instance a ~ () => Fmt.Internal.Core.FromBuilder (GHC.Types.IO a)
- Fmt.Internal.Core: instance a ~ GHC.Types.Char => Fmt.Internal.Core.FromBuilder [a]
- Fmt.Internal.Generic: instance Fmt.Internal.Generic.Buildable' a => Fmt.Internal.Generic.Buildable' (Data.List.NonEmpty.NonEmpty a)
- Fmt.Internal.Template: instance Data.Semigroup.Semigroup Fmt.Internal.Template.Format
+ Fmt: pretty :: (Buildable a, FromBuilder b) => a -> b
+ Fmt: prettyLn :: (Buildable a, FromBuilder b) => a -> b
+ Fmt.Internal.Core: instance (a ~ ()) => Fmt.Internal.Core.FromBuilder (GHC.Types.IO a)
+ Fmt.Internal.Core: instance (a ~ GHC.Types.Char) => Fmt.Internal.Core.FromBuilder [a]
+ Fmt.Internal.Core: instance Fmt.Internal.Core.FromBuilder Data.ByteString.Builder.Internal.Builder
+ Fmt.Internal.Core: instance Fmt.Internal.Core.FromBuilder Data.ByteString.Internal.ByteString
+ Fmt.Internal.Core: instance Fmt.Internal.Core.FromBuilder Data.ByteString.Lazy.Internal.ByteString
+ Fmt.Internal.Core: pretty :: (Buildable a, FromBuilder b) => a -> b
+ Fmt.Internal.Core: prettyLn :: (Buildable a, FromBuilder b) => a -> b
+ Fmt.Internal.Generic: instance Fmt.Internal.Generic.Buildable' a => Fmt.Internal.Generic.Buildable' (GHC.Base.NonEmpty a)
+ Fmt.Internal.Template: instance GHC.Base.Semigroup Fmt.Internal.Template.Format
- Fmt: data Builder :: *
+ Fmt: data Builder

Files

CHANGELOG.md view
@@ -1,3 +1,15 @@+# 0.6.1++* Added `instance FromBuilder ByteString` (for both lazy and strict+  bytestrings) and `instance FromBuilder BS.Builder`. These instances+  generate UTF8-encoded bytestrings. This allows producing formatting+  strings for various HTTP libraries that are intent on using `ByteString`+  for text.++* Added `pretty :: (Buildable a, FromBuilder b) => a -> b` for formatting+  anything as `Buildable`. There's also `prettyLn` for consistency with+  `fmt` and `fmtLn`.+ # 0.6  * Switched to `Buildable` from `formatting` (since `text-format` is
fmt.cabal view
@@ -1,5 +1,5 @@ name:                fmt-version:             0.6+version:             0.6.1 synopsis:            A new formatting library description:   A new formatting library that tries to be simple to understand while still@@ -46,7 +46,7 @@ maintainer:          yom@artyom.me -- copyright: category:            Text-tested-with:         GHC == 7.10.3, GHC == 8.0.2, GHC == 8.2.2, GHC == 8.4.1+tested-with:         GHC == 7.10.3, GHC == 8.0.2, GHC == 8.2.2, GHC == 8.4.4, GHC == 8.6.1 build-type:          Simple extra-source-files:  CHANGELOG.md                      tests/doctest-config.json
lib/Fmt.hs view
@@ -53,8 +53,8 @@   Format,    -- * Helper functions-  fmt,-  fmtLn,+  fmt, fmtLn,+  pretty, prettyLn,    Builder,   Buildable(..),@@ -348,7 +348,6 @@  {- docs ~~~~~~~~~~~~~~~~~~~~-* write explicitly that 'build' can be used and is useful sometimes * mention that fmt doesn't do the neat thing that formatting does with (<>)   (or maybe it does? there's a monoid instance for functions after all,   though I might also have to write a IsString instance for (a -> Builder))
lib/Fmt/Internal/Core.hs view
@@ -9,9 +9,14 @@ import           Data.Monoid ((<>)) #endif import qualified Data.Text as T+import qualified Data.Text.Encoding as T import qualified Data.Text.Lazy as TL import qualified Data.Text.Lazy.IO as TL+import qualified Data.Text.Lazy.Encoding as TL import           Data.Text.Lazy.Builder hiding (fromString)+import qualified Data.ByteString as BS+import qualified Data.ByteString.Lazy as BSL+import qualified Data.ByteString.Builder as BB import           Formatting.Buildable (Buildable(..))  @@ -39,6 +44,18 @@   fromBuilder = toLazyText   {-# INLINE fromBuilder #-} +instance FromBuilder BS.ByteString where+  fromBuilder = T.encodeUtf8 . TL.toStrict . toLazyText+  {-# INLINE fromBuilder #-}++instance FromBuilder BSL.ByteString where+  fromBuilder = TL.encodeUtf8 . toLazyText+  {-# INLINE fromBuilder #-}++instance FromBuilder BB.Builder where+  fromBuilder = TL.encodeUtf8Builder . toLazyText+  {-# INLINE fromBuilder #-}+ instance (a ~ ()) => FromBuilder (IO a) where   fromBuilder = TL.putStr . toLazyText   {-# INLINE fromBuilder #-}@@ -96,10 +113,10 @@ -- Functions ---------------------------------------------------------------------------- -{- | 'fmt' converts things to 'String', 'Text' or 'Builder'.+{- | 'fmt' converts things to 'String', 'T.Text', 'BS.ByteString' or 'Builder'.  Most of the time you won't need it, as strings produced with ('+|') and-('|+') can already be used as 'String', 'Text', etc. However, combinators+('|+') can already be used as 'String', 'T.Text', etc. However, combinators like 'listF' can only produce 'Builder' (for better type inference), and you need to use 'fmt' on them. @@ -117,3 +134,15 @@ fmtLn :: FromBuilder b => Builder -> b fmtLn = fromBuilder . (<> "\n") {-# INLINE fmtLn #-}++{- | 'pretty' shows a value using its 'Buildable' instance.+-}+pretty :: (Buildable a, FromBuilder b) => a -> b+pretty = fmt . build+{-# INLINE pretty #-}++{- | Like 'pretty', but appends a newline.+-}+prettyLn :: (Buildable a, FromBuilder b) => a -> b+prettyLn = fmtLn . build+{-# INLINE prettyLn #-}
lib/Fmt/Internal/Formatters.hs view
@@ -80,7 +80,7 @@     ls  -> k <> ":\n" <>            mconcat ["  " <> fromLazyText s <> "\n" | s <- ls] -{- | Put words between elements.+{- | Put spaces between elements.  >>> fmt $ unwordsF ["hello", "world"] hello world
tests/Main.hs view
@@ -21,6 +21,7 @@ import Data.Map (Map) import qualified Data.ByteString as BS import qualified Data.ByteString.Lazy as BSL+import qualified Data.ByteString.Builder as BB -- Generics import GHC.Generics -- Call stacks@@ -109,8 +110,14 @@     ("a"+|n|+"b" :: Text) `shouldBe` "a25b"   it "Lazy Text" $     ("a"+|n|+"b" :: TL.Text) `shouldBe` "a25b"-  it "Builder" $+  it "ByteString" $+    ("a"+|n|+"b" :: BS.ByteString) `shouldBe` "a25b"+  it "Lazy ByteString" $+    ("a"+|n|+"b" :: BSL.ByteString) `shouldBe` "a25b"+  it "Text Builder" $     ("a"+|n|+"b" :: Builder) `shouldBe` "a25b"+  it "ByteString Builder" $+    BB.toLazyByteString ("a"+|n|+"b" :: BB.Builder) `shouldBe` "a25b"  ---------------------------------------------------------------------------- -- Tests for various simple formatters