-
Notifications
You must be signed in to change notification settings - Fork 0
/
28text.hs
60 lines (38 loc) · 1.1 KB
/
28text.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
{-# LANGUAGE OverloadedStrings #-}
import qualified Data.Text as T
import Data.Semigroup
--T.pack :: String -> T.Text
--T.unpack :: T.Text -> String
key = "MysTRING"
keyText = T.pack key
aWord :: T.Text
aWord = "Cheese"
main :: IO ()
main = do
print aWord
sampleInput :: T.Text
sampleInput = "this\nis\ninput"
-- to join
joined = T.unlines ["1234","32435","sdg"]
--------------------
breakText :: T.Text
breakText = "simple"
exampleText :: T.Text
exampleText = "This is simple to do"
split = T.splitOn breakText exampleText
-- join using a particular delimiter
-- interlace
joinedUsingCustomDelimiter = T.intercalate "---" ["123","456","789"]
-- joinedUsingCustomDelimiter
-- "123---456---789"
combinedTextMonoid :: T.Text
combinedTextMonoid = mconcat ["some"," ","text"]
{-Create your own version of T.lines and T.unlines by using splitOn and T.intercalate.-}
-- T.lines:
myLines :: T.Text -> [T.Text]
myLines = T.splitOn "\n"
-- T.unlines
myUnlines :: [T.Text] -> T.Text
myUnlines = T.intercalate "\n"
----------------------------------------------
----------------- Unicode --------------------