Proposal: Add chop function to Data.List
Lennart Augustsson
lennart at augustsson.net
Tue Dec 14 16:38:11 CET 2010
Yes, chop can be easily written in terms of unfoldr. But the chop function
fits better with other existing list functions, like I tried to illustrate
with my examples.
-- Lennart
On Tue, Dec 14, 2010 at 10:40 AM, Stefan Holdermans <
stefan at vectorfabrics.com> wrote:
> Henning,
>
> >> 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
>
>
> > Is the difference between 'unfoldr' and 'chop' just the Maybe result type
> of f?
>
>
> Yes.
>
> chop f = unfoldr g
> where
> g [] = Nothing
> g as = Just (f as)
>
> Cheers,
>
> Stefan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/libraries/attachments/20101214/77975fcc/attachment.htm>
More information about the Libraries
mailing list