[Haskell-cafe] Splitting a string into chunks
robdockins at fastmail.fm
Fri Jan 13 16:50:11 EST 2006
On Jan 13, 2006, at 4:35 PM, Jon Fairbairn wrote:
> On 2006-01-13 at 13:32PST Jared Updike wrote:
>> That works except it loses single newline characters.
>> let s = "1234\n5678\n\nabcdefghijklmnopq\n\n,,.,.,."
>> Prelude> blocks s
> Also the argument to groupBy ought to be some sort of
> equivalence relation.
Humm, still not reflexive. You need xor.
> blocks = map unlines
> . filter (all $ not . null)
> . groupBy (\a b -> not (null b|| null a))
> . lines
> ... but that suffers from the somewhat questionable
> properties of lines and unlines.
> -- Jón Fairbairn Jon.Fairbairn at
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
Speak softly and drive a Sherman tank.
Laugh hard; it's a long way to the bank.
More information about the Haskell-Cafe