[Haskell-cafe] Splitting a string into chunks

Jon Fairbairn Jon.Fairbairn at cl.cam.ac.uk
Fri Jan 13 17:17:53 EST 2006


On 2006-01-13 at 16:50EST Robert Dockins wrote:
> 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
> >> ["12345678","abcdefghijklmnopq",",,.,.,."]
> >
> > Also the argument to groupBy ought to be some sort of
> > equivalence relation.
> 
> Humm, still not reflexive.  You need xor.

ugh, yes. How about 

> 
> > blocks = map unlines
> >          . filter (all $ not . null)
> >          . groupBy 

                       (\a b -> null b == null a)
> >          . lines

?
-- 
Jón Fairbairn                              Jon.Fairbairn at cl.cam.ac.uk




More information about the Haskell-Cafe mailing list