Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Control.Category ((>>>))
- import Data.List (intercalate)
- data Product = Product { name :: String
- , vendor :: String
- , price :: Float
- } deriving (Read)
- instance Show Product where
- show (Product name' vendor' price') = vendor' ++ " " ++ name' ++ " — " ++ (show price')
- isValid p = all ($ p) predicates
- where
- nameValid = name >>> not . null
- vendorValid = vendor >>> not . null
- priceValid = price >>> (> 0)
- predicates = [nameValid, vendorValid, priceValid]
- parseProducts :: String -> [Product]
- parseProducts = map read . lines
- main :: IO ()
- main = getContents >>= mapM_ print . filter isValid . parseProducts
Add Comment
Please, Sign In to add comment