Skip to content

Commit

Permalink
finished exercises for Course.Interactive
Browse files Browse the repository at this point in the history
  • Loading branch information
miladz68 committed Jan 3, 2017
1 parent 63ccd6d commit 1217782
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ After this, the following progression of modules is recommended:
* `Course.Parser` -> Done
* `Course.MoreParser` -> Done
* `Course.JsonParser` -> Done
* `Course.Interactive`
* `Course.Interactive` -> Done
* `Course.Anagrams`
* `Course.FastAnagrams`
* `Course.Cheque`
28 changes: 22 additions & 6 deletions src/Course/Interactive.hs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,10 @@ data Op =
-- /Tip:/ @putStrLn :: String -> IO ()@ -- Prints a string and then a new line to standard output.
convertInteractive ::
IO ()
convertInteractive =
error "todo: Course.Interactive#convertInteractive"
convertInteractive = do
putStr "enter a String to convert to upper case: "
str <- getLine
putStrLn (toUpper <$> str)

-- |
--
Expand All @@ -110,8 +112,13 @@ convertInteractive =
-- /Tip:/ @putStrLn :: String -> IO ()@ -- Prints a string and then a new line to standard output.
reverseInteractive ::
IO ()
reverseInteractive =
error "todo: Course.Interactive#reverseInteractive"
reverseInteractive = do
putStr "enter file name to reverse its content: "
address <- getLine
putStr "enter file name to write converted data to: "
dest <- getLine
content <- readFile address
writeFile dest (reverse content)

-- |
--
Expand All @@ -136,8 +143,17 @@ reverseInteractive =
-- /Tip:/ @putStrLn :: String -> IO ()@ -- Prints a string and then a new line to standard output.
encodeInteractive ::
IO ()
encodeInteractive =
error "todo: Course.Interactive#encodeInteractive"
encodeInteractive = do
putStr "enter a url to be encoded: "
url <- getLine
putStrLn $ encodeURL url

encodeURL :: Chars -> Chars
encodeURL = foldRight (\s acc -> case s of
' ' -> "%20" ++ acc
'\t' -> "%09" ++ acc
'\"' -> "%22" ++ acc
_ -> s :. acc) Nil

interactive ::
IO ()
Expand Down

0 comments on commit 1217782

Please sign in to comment.