What is your favourite cleverly written functional code?
- by sdcvvc
What are your favourite short, mind-blowing snippets in functional languages?
My two favourite ones are (Haskell):
powerset = filterM (const [True, False])
foldl f v xs = foldr (\x g a -> g (f a x)) id xs v -- from Hutton's tutorial
(I tagged the question as Haskell, but examples in all languages - including non-FP ones - are welcome as long as they are in functional spirit.)