[Haskell-cafe] Removing alternate items from a list

Christopher Done chrisdone at googlemail.com
Tue Jun 8 12:12:07 EDT 2010


On 8 June 2010 15:13, Jürgen Doser <jurgen.doser at gmail.com> wrote:
> El dom, 06-06-2010 a las 14:46 +0000, R J escribió:
>> What's the cleanest definition for a function f :: [a] -> [a] that
>> takes a list and returns the same list, with alternate items removed?
>>  e.g., f [0, 1, 2, 3, 4, 5] = [1,3,5]?
>
> adding another suggestion:
>
> import Data.Either(rights)
>
> f = rights . zipWith ($) (cycle [Left,Right])

Ohhh. Nice.


More information about the Haskell-Cafe mailing list