I am looking for code that can simultaneously display and align lists and maybs. I found such a flat map in this section :
flatMap :: (t -> [a]) -> [t] -> [a] flatMap _ [] = [] flatMap f (x:xs) = fx ++ flatMap f xs
This works great:
> flatMap id [[],[1,2],[3],[],[4,5,6]] [1,2,3,4,5,6]
The only problem is that it does not work for Maybes. Instead, I should use Data.Maybe.mapMaybe :
> Data.Maybe.mapMaybe id [Just 1, Nothing, Just 2, Just 3, Nothing] [1,2,3]
Is there one built-in function that can handle both lists and maybes (and possibly some other types)?
source share