[Haskell-cafe] Splitting a string into chunks

2006-01-13 Thread Adam Turoff
Hi, I'm trying to split a string into a list of substrings, where substrings are delimited by blank lines. This feels like it *should* be a primitive operation, but I can't seem to find one that works. It's neither a fold nor a partition, since each chunk is separated by a 2-character sequence.

Re: [Haskell-cafe] Splitting a string into chunks

2006-01-13 Thread Sebastian Sylvan
On 1/13/06, Adam Turoff [EMAIL PROTECTED] wrote: Hi, I'm trying to split a string into a list of substrings, where substrings are delimited by blank lines. This feels like it *should* be a primitive operation, but I can't seem to find one that works. It's neither a fold nor a partition,

Re: [Haskell-cafe] Splitting a string into chunks

2006-01-13 Thread Sebastian Sylvan
On 1/13/06, Sebastian Sylvan [EMAIL PROTECTED] wrote: On 1/13/06, Adam Turoff [EMAIL PROTECTED] wrote: Hi, I'm trying to split a string into a list of substrings, where substrings are delimited by blank lines. This feels like it *should* be a primitive operation, but I can't seem to

Re: [Haskell-cafe] Splitting a string into chunks

2006-01-13 Thread Jared Updike
That works except it loses single newline characters. let s = 1234\n5678\n\nabcdefghijklmnopq\n\n,,.,.,. Prelude blocks s [12345678,abcdefghijklmnopq,,,.,.,.] Jared. On 1/13/06, Sebastian Sylvan [EMAIL PROTECTED] wrote: On 1/13/06, Sebastian Sylvan [EMAIL PROTECTED] wrote: On 1/13/06, Adam

Re: [Haskell-cafe] Splitting a string into chunks

2006-01-13 Thread Jon Fairbairn
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. blocks =

Re: [Haskell-cafe] Splitting a string into chunks

2006-01-13 Thread Robert Dockins
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

Re: [Haskell-cafe] Splitting a string into chunks

2006-01-13 Thread Adam Turoff
On 1/13/06, Sebastian Sylvan [EMAIL PROTECTED] wrote: blocks = map concat . groupBy (const (not . null)) . lines Thanks. That's a little more involved than I was looking for, but that certainly looks better than pattern matching on ('\n':'\n':rest). ;-) For the record, lines removes the