[Assorted-commits] SF.net SVN: assorted:[1617] sandbox/trunk/src/one-off-scripts
Brought to you by:
yangzhang
From: <yan...@us...> - 2010-04-03 19:01:22
|
Revision: 1617 http://assorted.svn.sourceforge.net/assorted/?rev=1617&view=rev Author: yangzhang Date: 2010-04-03 19:01:16 +0000 (Sat, 03 Apr 2010) Log Message: ----------- added ashdown-residents, an early haskell script Added Paths: ----------- sandbox/trunk/src/one-off-scripts/ashdown-residents/ sandbox/trunk/src/one-off-scripts/ashdown-residents/README sandbox/trunk/src/one-off-scripts/ashdown-residents/res.lhs sandbox/trunk/src/one-off-scripts/ashdown-residents/res2.lhs Added: sandbox/trunk/src/one-off-scripts/ashdown-residents/README =================================================================== --- sandbox/trunk/src/one-off-scripts/ashdown-residents/README (rev 0) +++ sandbox/trunk/src/one-off-scripts/ashdown-residents/README 2010-04-03 19:01:16 UTC (rev 1617) @@ -0,0 +1,2 @@ +this is one of the earliest haskell scripts i've written (along with a revised +version based on feedback?); kept here for nostalgia/posterity Added: sandbox/trunk/src/one-off-scripts/ashdown-residents/res.lhs =================================================================== --- sandbox/trunk/src/one-off-scripts/ashdown-residents/res.lhs (rev 0) +++ sandbox/trunk/src/one-off-scripts/ashdown-residents/res.lhs 2010-04-03 19:01:16 UTC (rev 1617) @@ -0,0 +1,37 @@ +#!/usr/bin/env runhaskell + +> module Main where +> +> import System ( getArgs ) +> import Data.Char ( toLower ) +> import Data.List ( isSuffixOf ) +> import PreludeExts ( joinList, split ) +> import Maybe ( fromJust, fromMaybe, isJust, isNothing ) +> import Control.Monad ( guard, mplus ) +> +> dropSuffix suffix xs = if suffix `isSuffixOf` xs +> then take (length xs - length suffix) xs +> else xs +> +> main = do +> argv <- getArgs +> interact $ unlines . processLines . lines +> +> processLines :: [String] -> [String] +> processLines ls = [ after | before <- ls, Just after <- [processLine before]] +> where processLine :: String -> Maybe String +> processLine x = do let fields = split "," x +> res <- processFields fields +> return (joinList "," res) +> processFields :: [String] -> Maybe [String] +> processFields [room,fname,lname,gender,email1,email2,_,_,_,_,_,_] = +> let e1 = map toLower email1 +> e2 = map toLower email2 +> suffix = "@mit.edu" +> fix email = [room,fname,lname,gender,dropSuffix suffix email] +> in do guard (suffix `isSuffixOf` e1) +> return (fix e1) +> `mplus` +> do guard (suffix `isSuffixOf` e2) +> return (fix e2) +> processFields _ = Nothing \ No newline at end of file Property changes on: sandbox/trunk/src/one-off-scripts/ashdown-residents/res.lhs ___________________________________________________________________ Added: svn:executable + * Added: sandbox/trunk/src/one-off-scripts/ashdown-residents/res2.lhs =================================================================== --- sandbox/trunk/src/one-off-scripts/ashdown-residents/res2.lhs (rev 0) +++ sandbox/trunk/src/one-off-scripts/ashdown-residents/res2.lhs 2010-04-03 19:01:16 UTC (rev 1617) @@ -0,0 +1,33 @@ +#!/usr/bin/env runhaskell + +> module Main where +> +> import System ( getArgs ) +> import Data.Char ( toLower ) +> import Data.List ( isSuffixOf ) +> import PreludeExts ( joinList, split ) +> import Maybe ( fromJust, fromMaybe, isJust, isNothing ) +> +> dropSuffix suffix xs = if suffix `isSuffixOf` xs +> then take (length xs - length suffix) xs +> else xs +> +> main = do +> argv <- getArgs +> interact $ unlines . processLines . lines +> +> processLines :: [String] -> [String] +> processLines ls = [ fromJust after | before <- ls, after <- [processLine before], isJust after ] +> where processLine :: String -> Maybe String +> processLine = (\x -> if isNothing x then Nothing else Just $ joinList "," $ fromJust x) . processFields . split "," +> processFields :: [String] -> Maybe [String] +> processFields [room,fname,lname,gender,email1,email2,_,_,_,_,_,_] = +> let e1 = map toLower email1 +> e2 = map toLower email2 +> suffix = "@mit.edu" +> fix email = [room,fname,lname,gender,dropSuffix suffix email] +> in if suffix `isSuffixOf` e1 +> then Just $ fix e1 +> else if suffix `isSuffixOf` e2 +> then Just $ fix e2 +> else Nothing Property changes on: sandbox/trunk/src/one-off-scripts/ashdown-residents/res2.lhs ___________________________________________________________________ Added: svn:executable + * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |