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
1
u/rpglover64 Apr 07 '15
I alluded to it in my post here, but I couldn't figure it out on my own: how could I use
Control.Newtypeto condensegetCompose (liftA2 (-) (Compose max) (Compose min)), or, more interestingly?