I don't really care if the function is called chop or not.
On 12/13/10 12:17 PM, Lennart Augustsson wrote: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).
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.
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@haskell.org
http://www.haskell.org/mailman/listinfo/libraries