The task is to use just one passthrough using foldr
or foldl
.
I use this decision:
evenOnly = fst . foldr (\x (y1, y2) -> (y2, x:y1)) ([],[])
Pretty good for finite lists. If I try evenOnly [1,2..]
I'll got a fail. I know it's because of suspended caclulations, but how can I otherwise split the list or how to pass additional information about list positions or something to the calculations which begin at the end of the list?