packages feed

om-show (empty) → 0.1.2.6

raw patch · 5 files changed

+170/−0 lines, 5 filesdep +aesondep +basedep +textsetup-changed

Dependencies added: aeson, base, text

Files

+ LICENSE view
@@ -0,0 +1,21 @@+MIT License++Copyright (c) 2022 Owens Murray, LLC.++Permission is hereby granted, free of charge, to any person obtaining a copy+of this software and associated documentation files (the "Software"), to deal+in the Software without restriction, including without limitation the rights+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the Software is+furnished to do so, subject to the following conditions:++The above copyright notice and this permission notice shall be included in all+copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE+SOFTWARE.
+ README.md view
@@ -0,0 +1,57 @@+# om-show++Haskell utilities for turning values into string representations. It is mainly+just a couple of very useful functions that eliminate a lot of conversion to+from text types. It's so small that I can just post the entire source code in+this README:++```haskell+{-# LANGUAGE DerivingStrategies #-}+{-# LANGUAGE GeneralizedNewtypeDeriving #-}++{- | Utilities for showing string-like things. -}+module OM.Show (+  showt,+  showj,+  ShowJ(..),+) where+++import Data.Aeson (encode, ToJSON)+import Data.String (IsString, fromString)+import qualified Data.Text.Lazy as TL+import qualified Data.Text.Lazy.Encoding as TLE+++{- | Like 'show', but for any string-like thing. -}+showt :: (Show a, IsString b) => a -> b+showt = fromString . show+++{- |+  Show the JSON representation as any kind of string-like thing.+  Primarily useful for dumping JSON values into log messages without having to+  jump through too many hoops.+-}+showj :: (ToJSON a, IsString b) => a -> b+showj = fromString . TL.unpack . TLE.decodeUtf8 . encode+++{- |+  Wrapper whose 'Show' instance outputs JSON.++  Especially useful with `-XDerivingVia`+  e.g.++  > newtype Foo = Foo SomeType+  >   deriving Show via (ShowJ SomeType)++  This will cause @show (foo :: Foo) to output the JSON representation+  of SomeType.+-}+newtype ShowJ a = ShowJ a+  deriving stock (Eq, Ord)+  deriving newtype (ToJSON)+instance (ToJSON a) => Show (ShowJ a) where+  show = showj+```
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ om-show.cabal view
@@ -0,0 +1,40 @@+cabal-version:       3.0+name:                om-show+version:             0.1.2.6+synopsis:            Utilities for showing string-like things.+description:         Utilities for showing string-like things.+homepage:            https://github.com/owensmurray/om-show+license:             MIT+license-file:        LICENSE+author:              Rick Owens+maintainer:          rick@owensmurray.com+copyright:           2021 Owens Murray, LLC.+category:            Text+build-type:          Simple+extra-source-files:+  README.md+  LICENSE+++common dependencies+  build-depends:+    , aeson >= 2.0.3.0  && < 2.1+    , base  >= 4.15.0.0 && < 4.16+    , text  >= 1.2.5.0  && < 1.3++common warnings+  ghc-options:+    -Wall+    -Wmissing-deriving-strategies+    -Wmissing-export-lists+    -Wmissing-import-lists+    -Wredundant-constraints++library+  import: dependencies, warnings+  exposed-modules:     +    OM.Show+  -- other-modules:       +  -- other-extensions:    +  hs-source-dirs: src+  default-language: Haskell2010
+ src/OM/Show.hs view
@@ -0,0 +1,50 @@+{-# LANGUAGE DerivingStrategies #-}+{-# LANGUAGE GeneralizedNewtypeDeriving #-}++{- | Utilities for showing string-like things. -}+module OM.Show (+  showt,+  showj,+  ShowJ(..),+) where+++import Data.Aeson (encode, ToJSON)+import Data.String (IsString, fromString)+import qualified Data.Text.Lazy as TL+import qualified Data.Text.Lazy.Encoding as TLE+++{- | Like 'show', but for any string-like thing. -}+showt :: (Show a, IsString b) => a -> b+showt = fromString . show+++{- |+  Show the JSON representation as any kind of string-like thing.+  Primarily useful for dumping JSON values into log messages without having to+  jump through too many hoops.+-}+showj :: (ToJSON a, IsString b) => a -> b+showj = fromString . TL.unpack . TLE.decodeUtf8 . encode+++{- |+  Wrapper whose 'Show' instance outputs JSON.++  Especially useful with `-XDerivingVia`+  e.g.++  > newtype Foo = Foo SomeType+  >   deriving Show via (ShowJ SomeType)++  This will cause @show (foo :: Foo) to output the JSON representation+  of SomeType.+-}+newtype ShowJ a = ShowJ a+  deriving stock (Eq, Ord)+  deriving newtype (ToJSON)+instance (ToJSON a) => Show (ShowJ a) where+  show = showj++