[Haskell-cafe] Removing alternate items from a list
chrisdone at googlemail.com
Tue Jun 8 08:20:44 EDT 2010
Can't forget fix in a game of code golf!
> (fix $ \f (x:_: xs) -> x : f xs) [1..]
2010/6/8 Yitzchak Gale <gale at sefer.org>:
> R J wrote:
>> 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]?
> f = map head . takeWhile (not . null) . iterate (drop 2) . drop 1
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
More information about the Haskell-Cafe