Skip empty lines
This commit is contained in:
parent
516a0173f7
commit
e2278ad892
4
RPN.hs
4
RPN.hs
@ -8,10 +8,10 @@ main :: IO ()
|
||||
main = io (show . rpn)
|
||||
|
||||
io :: (String -> String) -> IO ()
|
||||
io f = interact (unlines . map f . lines)
|
||||
io f = interact (unlines . map f . filter (not . null) . lines)
|
||||
|
||||
rpn :: String -> Either String Double
|
||||
rpn = return . head <=< foldM parse [] . words
|
||||
rpn = foldM parse [] . words >=> return . head
|
||||
|
||||
parse :: [Double] -> String -> Either String [Double]
|
||||
parse (y:x:xs) (flip lookup dyad -> Just f) = Right (f x y : xs)
|
||||
|
Loading…
Reference in New Issue
Block a user