[Assorted-commits] SF.net SVN: assorted: [199] movie-lookup/trunk/src
Brought to you by:
yangzhang
From: <yan...@us...> - 2007-12-26 09:20:31
|
Revision: 199 http://assorted.svn.sourceforge.net/assorted/?rev=199&view=rev Author: yangzhang Date: 2007-12-26 01:20:30 -0800 (Wed, 26 Dec 2007) Log Message: ----------- added Viewer in scala and haskell Added Paths: ----------- movie-lookup/trunk/src/Viewer.hs movie-lookup/trunk/src/Viewer.scala Added: movie-lookup/trunk/src/Viewer.hs =================================================================== --- movie-lookup/trunk/src/Viewer.hs (rev 0) +++ movie-lookup/trunk/src/Viewer.hs 2007-12-26 09:20:30 UTC (rev 199) @@ -0,0 +1,23 @@ +module Main where + +import Control.Arrow +import Data.ByteString.Char8 (ByteString) +import qualified Data.ByteString.Char8 as BS +import System.Environment + +-- Commons + +tryRead s = case reads s of + [(x, "")] -> Just x + _ -> Nothing + +-- Viewer + +main = do + args <- getArgs + let thresh = read (args !! 0) + BS.interact $ BS.lines >>> filter (ratedAbove thresh) >>> BS.unlines + +ratedAbove :: Int -> ByteString -> Bool +ratedAbove thresh = + BS.words >>> last >>> BS.unpack >>> tryRead >>> maybe False (> thresh) Added: movie-lookup/trunk/src/Viewer.scala =================================================================== --- movie-lookup/trunk/src/Viewer.scala (rev 0) +++ movie-lookup/trunk/src/Viewer.scala 2007-12-26 09:20:30 UTC (rev 199) @@ -0,0 +1,9 @@ +import commons.Control._ +import commons.Io._ + +using (TextReader(System.in)) { + _.readLines filter {x => + try { (Integer parseInt (x split " --- " last)) > 60 } + catch { case ex: Exception => false } + } foreach println +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |