Skip to content

Commit

Permalink
Add ToText type class
Browse files Browse the repository at this point in the history
  • Loading branch information
newhoggy committed Nov 8, 2024
1 parent b420b96 commit 89ad33b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions hw-prelude.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,6 @@ library
HaskellWorks.IO.Network.Socket
HaskellWorks.IO.Process
HaskellWorks.Prelude
HaskellWorks.ToText
HaskellWorks.Unsafe
hs-source-dirs: src
25 changes: 25 additions & 0 deletions src/HaskellWorks/ToText.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
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 = T.pack

instance ToText Text where
toText = id

instance ToText LT.Text where
toText = LT.toStrict

instance ToText TB.Builder where
toText = LT.toStrict . TB.toLazyText

0 comments on commit 89ad33b

Please sign in to comment.