module HaskellWorks.ToText
  ( ToText (..)
  ) where

import           Data.Function
import           Data.String            (String)
import           Data.Text              (Text)
import qualified Data.Text              as T
import qualified Data.Text.Lazy         as LT
import qualified Data.Text.Lazy.Builder as TB

class ToText a where
  toText :: a -> Text

instance ToText String where
  toText :: String -> Text
toText = String -> Text
T.pack

instance ToText Text where
  toText :: Text -> Text
toText = Text -> Text
forall a. a -> a
id

instance ToText LT.Text where
  toText :: Text -> Text
toText = Text -> Text
LT.toStrict

instance ToText TB.Builder where
  toText :: Builder -> Text
toText = Text -> Text
LT.toStrict (Text -> Text) -> (Builder -> Text) -> Builder -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Builder -> Text
TB.toLazyText