What are some of your favorite “useful” Haskell oneliners? There are some really well-known elegant ones such as the lazy fibonacci sequence:
fibs = 0 : 1 : zipWith (+) fibs (tail fibs)
But I don’t need that sequence often in my day job…
So one I particularly like is when you have a HashMap
with Maybe a
values. Data.HashMap.Strict
does not provide a catMaybes
to throw away the Nothing
s, but you can use:
HMS.mapMaybe id
Which is a really cool example of how the id
function is useful!