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?" ]