[Haskell-beginners] list splitting - nice implementation?
Tobias Brandt
tob.brandt at googlemail.com
Sun Nov 18 11:53:23 CET 2012
On 18 November 2012 11:33, Kim-Ee Yeoh <ky3 at atamo.com> wrote:
> On Sun, Nov 18, 2012 at 4:47 PM, Tobias Brandt <tob.brandt at googlemail.com>
> wrote:
>
> split xs = getSnds $ span (uncurry (<)) $ zip xs (tail xs)
>> where getSnds (as, bs) = (map snd as, map snd bs)
>>
>
> You could prepend negative infinity to not lose the first element.
>
>
Oops, didn't noticed that, nice catch. I'd rather do the following, as it
works for all types that can be compared with (<), not just for numbers:
split xs = getSnds $ span (uncurry (<)) $ zip xs (tail xs)
where getSnds (as, bs) = (head xs : map snd as, map snd bs)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20121118/4378a91e/attachment.htm>
More information about the Beginners
mailing list