
On Mon, 13 Dec 2010, 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.
Is the difference between 'unfoldr' and 'chop' just the Maybe result type of f?
I first encountered this function around 1981 when I was talking to S?ren Holmstr?m about this recursion pattern and he said that he had also observed it and he called the function chopList. Ever since then I've used chopList a lot, but unfortunately I always have to make my own definition of this common function.
To work around this problem I have written utility-ht for the basic functions that I need all the time.