diff options
Diffstat (limited to 'Haskell-book/09/src/PoemLines.purs')
| -rw-r--r-- | Haskell-book/09/src/PoemLines.purs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/Haskell-book/09/src/PoemLines.purs b/Haskell-book/09/src/PoemLines.purs new file mode 100644 index 0000000..05a9a86 --- /dev/null +++ b/Haskell-book/09/src/PoemLines.purs @@ -0,0 +1,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?" ] |
