@@ -1,3 +1,13 @@
1+{-|
2+Module: Squeal.PostgreSQL.PrettyPrint
3+Description: Pretty print helper functions
4+Copyright: (c) Eitan Chatav, 2017
5+Maintainer: eitan@morphism.tech
6+Stability: experimental
7+
8+Pretty print helper functions.
9+-}
10+
111{-# LANGUAGE
212 MagicHash
313 , OverloadedStrings
@@ -18,15 +28,19 @@ import GHC.TypeLits
1828
1929import qualified Data.ByteString as ByteString
2030
31+-- | Parenthesize a `ByteString`.
2132parenthesized :: ByteString -> ByteString
2233parenthesized str = "(" <> str <> ")"
2334
35+-- | Concatenate two `ByteString`s with a space between.
2436(<+>) :: ByteString -> ByteString -> ByteString
2537str1 <+> str2 = str1 <> " " <> str2
2638
39+-- | Comma separate a list of `ByteString`s.
2740commaSeparated :: [ByteString] -> ByteString
2841commaSeparated = ByteString.intercalate ", "
2942
43+-- | Comma separate the renderings of a heterogeneous list.
3044renderCommaSeparated
3145 :: SListI xs
3246 => (forall x. expression x -> ByteString)
@@ -36,6 +50,8 @@ renderCommaSeparated render
3650 . hcollapse
3751 . hmap (K . render)
3852
53+-- | Comma separate the `Maybe` renderings of a heterogeneous list, dropping
54+-- `Nothing`s.
3955renderCommaSeparatedMaybe
4056 :: SListI xs
4157 => (forall x. expression x -> Maybe ByteString)
@@ -46,5 +62,6 @@ renderCommaSeparatedMaybe render
4662 . hcollapse
4763 . hmap (K . render)
4864
65+-- | Render a promoted `Nat`.
4966renderNat :: KnownNat n => proxy n -> ByteString
5067renderNat (_ :: proxy n) = fromString (show (natVal' (proxy# :: Proxy# n)))