Skip to content

Commit 89ad33b

Browse files
committed
Add ToText type class
1 parent b420b96 commit 89ad33b

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

hw-prelude.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,5 +96,6 @@ library
9696
HaskellWorks.IO.Network.Socket
9797
HaskellWorks.IO.Process
9898
HaskellWorks.Prelude
99+
HaskellWorks.ToText
99100
HaskellWorks.Unsafe
100101
hs-source-dirs: src

src/HaskellWorks/ToText.hs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
module HaskellWorks.ToText
2+
( ToText (..)
3+
) where
4+
5+
import Data.Function
6+
import Data.String (String)
7+
import Data.Text (Text)
8+
import qualified Data.Text as T
9+
import qualified Data.Text.Lazy as LT
10+
import qualified Data.Text.Lazy.Builder as TB
11+
12+
class ToText a where
13+
toText :: a -> Text
14+
15+
instance ToText String where
16+
toText = T.pack
17+
18+
instance ToText Text where
19+
toText = id
20+
21+
instance ToText LT.Text where
22+
toText = LT.toStrict
23+
24+
instance ToText TB.Builder where
25+
toText = LT.toStrict . TB.toLazyText

0 commit comments

Comments
 (0)