Proposal: Add chop function to Data.List

Lennart Augustsson lennart at augustsson.net
Tue Dec 14 11:24:40 CET 2010


I don't really care if the function is called chop or not.
But in many cases it is used to chop a list into smaller pieces.

On Tue, Dec 14, 2010 at 12:00 AM, wren ng thornton <wren at freegeek.org>wrote:

> 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 nice
> function.
>
> --
> Live well,
> ~wren
>
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://www.haskell.org/mailman/listinfo/libraries
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/libraries/attachments/20101214/ebcb9f56/attachment.htm>


More information about the Libraries mailing list