[Haskell-cafe] csv one-liner

Simon Brenner olsner at gmail.com
Tue Sep 30 15:01:25 EDT 2008


Something like this perhaps:

writeFile "output.csv" . printCSV . map updateLine . fromRight =<<
parseCSVFromFile "input.csv"

(with fromRight = either (error "fromRight :: Left") id or something equivalent)

On 9/30/08, wman <666wman at gmail.com> wrote:
> I got asked how to do one particular thing in excel, which led to discssion
> with "our local MSOffice expert".
> During the discussion I stated that's it too much of a PITA and that I'd
> rather write a script.
>  Long story short, I promised him a one-liner to "show the power and beauty
> of Haskell".
>
> I got the csv package from hackage, modified the parseCSVFromFile so it's
> returns IO CSV rather than IO (Either ParseError CSV), and finished with
> following code
>
> (writeFile "output.csv") =<< (liftM printCSV $ liftM (map updateLine) $
> parseCSVFromFile "input.csv")
>
> Is there room for improvement ?
> Could it still be made into one-liner without modifying the csv module (and
> without resorting to
>  case parseCSVFromFile "input.csv" of { Left _ -> []; Right x -> x}
> kind of tricks) ?
>
>
> Thanks, wman.
>
> _______________________________________________
>  Haskell-Cafe mailing list
>  Haskell-Cafe at haskell.org
>  http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>


More information about the Haskell-Cafe mailing list