-- |
-- Module      :  ELynx.Tools.Text
-- Copyright   :  (c) Dominik Schrempf 2021
-- License     :  GPL-3.0-or-later
--
-- Maintainer  :  dominik.schrempf@gmail.com
-- Stability   :  unstable
-- Portability :  portable
--
-- Creation date: Thu Feb 14 13:24:53 2019.
--
-- indispensable tools for ByteString handling :).
module ELynx.Tools.Text
  ( -- * Text handling
    tShow,
    fromBs,
  )
where

import qualified Data.ByteString.Lazy.Char8 as BL
import Data.Text
  ( Text,
    pack,
  )
import Data.Text.Lazy (toStrict)
import Data.Text.Lazy.Encoding (decodeUtf8)

-- | Conversion to 'Text' from showable values.
tShow :: Show a => a -> Text
tShow :: a -> Text
tShow = String -> Text
pack (String -> Text) -> (a -> String) -> a -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> String
forall a. Show a => a -> String
show

-- | Conversion to 'Text' from bytestring.
fromBs :: BL.ByteString -> Text
fromBs :: ByteString -> Text
fromBs = Text -> Text
toStrict (Text -> Text) -> (ByteString -> Text) -> ByteString -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Text
decodeUtf8