summaryrefslogtreecommitdiff
path: root/lib/Util.hs
diff options
context:
space:
mode:
authorstuebinm2022-02-18 18:09:23 +0100
committerstuebinm2022-03-19 19:54:48 +0100
commit52bf0fa6dace596a4bd5b4e4229fbb9704fbf443 (patch)
tree971604d125e2faba93db8845224a2d43ee645935 /lib/Util.hs
parent53fb449b008e9b6aed9877b9d33f4026e454e0f9 (diff)
switch to universum prelude
also don't keep adjusted maps around if not necessary
Diffstat (limited to 'lib/Util.hs')
-rw-r--r--lib/Util.hs19
1 files changed, 6 insertions, 13 deletions
diff --git a/lib/Util.hs b/lib/Util.hs
index ffd9faa..1ffbbe5 100644
--- a/lib/Util.hs
+++ b/lib/Util.hs
@@ -6,31 +6,24 @@
-- concerns itself with wrangling haskell's string types
module Util
( mkProxy
- , showText
, PrettyPrint(..)
, printPretty
, naiveEscapeHTML
, layerIsEmpty
) where
+import Universum
+
import Data.Aeson as Aeson
-import Data.Proxy (Proxy (..))
-import Data.Set (Set)
import qualified Data.Set as S
-import Data.Text (Text)
import qualified Data.Text as T
import Tiled (Layer (layerData), PropertyValue (..),
Tileset (tilesetName), layerName, mkTiledId)
-
-- | helper function to create proxies
mkProxy :: a -> Proxy a
mkProxy = const Proxy
--- | haskell's many string types are FUN …
-showText :: Show a => a -> Text
-showText = T.pack . show
-
-- | a class to address all the string conversions necessary
-- when using Show to much that just uses Text instead
class PrettyPrint a where
@@ -44,7 +37,7 @@ instance PrettyPrint Text where
instance PrettyPrint Aeson.Value where
prettyprint = \case
Aeson.String s -> prettyprint s
- v -> (T.pack . show) v
+ v -> show v
instance PrettyPrint t => PrettyPrint (Set t) where
prettyprint = prettyprint . S.toList
@@ -53,8 +46,8 @@ instance PrettyPrint PropertyValue where
prettyprint = \case
StrProp str -> str
BoolProp bool -> if bool then "true" else "false"
- IntProp int -> showText int
- FloatProp float -> showText float
+ IntProp int -> show int
+ FloatProp float -> show float
-- | here since Unit is sometimes used as dummy type
instance PrettyPrint () where
@@ -70,7 +63,7 @@ instance PrettyPrint a => PrettyPrint [a] where
prettyprint = T.intercalate ", " . fmap prettyprint
printPretty :: PrettyPrint a => a -> IO ()
-printPretty = putStr . T.unpack . prettyprint
+printPretty = putStr . toString . prettyprint
-- | for long lists which shouldn't be printed out in their entirety