Proposal: Add chop function to Data.List
wren ng thornton
wren at freegeek.org
Tue Dec 14 01:00:23 CET 2010
On 12/13/10 12:17 PM, Lennart Augustsson wrote:
> I would like to propose the following function for inclusion in Data.List
> chop :: ([a] -> (b, [a])) -> [a] -> [b]
> chop _  = 
> chop f as = b : chop f as'
> where (b, as') = f as
> It's commonly occuring recursion pattern. Typically chop is called
> with some function that will consume an initial prefix of the list
> and produce a value and the rest of the list.
> The function is clearly related to unfoldr, but I find it more
> convenient to use in a lot of cases.
It's also deeply related to iteratees (for the obvious enumerator of a
list). The major difference is that iteratees enforce that the consuming
function must return a tail of the input stream, whereas this function
doesn't require that at all (for both good and ill).
The name "chop" seems a bit strange to me, but other than that it's a
More information about the Libraries