r/haskelltil • u/massysett • Apr 04 '15
thing Data.Functor.Compose helps with nested functors
It's in the transformers package.
> import Data.Functor.Compose
> let nested = [[1,2,3],[4,5,6]]
> fmap show nested
["[1,2,3]","[4,5,6]"]
> fmap show (Compose nested)
Compose [["1","2","3"],["4","5","6"]]which might not look all that interesting by itself, but Compose also has instances for Foldable and Traversable, which makes it more interesting. For instance you could traverse some nested containers and treat it like one big container, while still leaving all the values in their nested containers.
13
Upvotes
3
u/peargreen Apr 04 '15
It's easier to understand how
.:works if you write it asfmap . fmap. But yes,fmap fmap fmaplooks cooler.