summaryrefslogtreecommitdiff
path: root/Haskell-book/09/src/PoemLines.purs
blob: 05a9a8642b9976920e225222c5fb95ab565ae212 (plain)
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
module PoemLines where

import Data.Array ((:))
import Data.String (takeWhile, dropWhile, drop)
import Prelude

splitWith :: Char -> String -> Array String
splitWith _ "" = []
splitWith sep s = (takeWhile cond s) : (splitWith sep $ drop 1 $ dropWhile cond s)
    where cond x = x /= sep

myWords :: String -> Array String
myWords = splitWith ' '

firstSen :: String
firstSen = "Tyger Tyger, burning bright\n"
secondSen :: String
secondSen = "In the forests of the night\n"
thirdSen :: String
thirdSen = "What immortal hand or eye\n"
fourthSen :: String
fourthSen = "Could frame thy fearful symmetry?"

sentences :: String
sentences = firstSen <> secondSen <> thirdSen <> fourthSen
-- putStrLn sentences -- should print
-- Tyger Tyger, burning bright
-- In the forests of the night
-- What immortal hand or eye
-- Could frame thy fearful symmetry?

myLines :: String -> Array String
myLines = splitWith '\n'

got :: Array String
got = myLines sentences

shouldEqual :: Array String
shouldEqual = [ "Tyger Tyger, burning bright"
              , "In the forests of the night"
              , "What immortal hand or eye"
              , "Could frame thy fearful symmetry?" ]