[Haskell-cafe] Is this Parsec code idiomatic?
ben_moseley at mac.com
Fri Sep 4 16:03:00 EDT 2009
Or for a bit of variety:
selectPlus s = [cs | ('+':cs) <- lines s]
On 4 Sep 2009, at 20:40, Martijn van Steenbergen wrote:
> Hi Serge,
> Serge LE HUITOUZE wrote:
>> I'm asking some advice on a small piece of code representing a
>> simplified version of a treatment I need to perform.
>> I have a line-oriented string/file, from which I want to extract
>> only a substring of those lines starting with char '+' (the detail
>> of the extraction is irrelevant here, I'll just return what follows
>> the '+').
> This isn't really answering your question, but I thought I'd share
> anyway: why use Parsec to retrieve those lines? It seems a simple
> function is a lot easier:
> selectPlus :: String -> [String]
> selectPlus = map tail . filter ((== '+') . head) . lines
> I hope this helps you.
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
More information about the Haskell-Cafe