The lens provides the traverseOf function, which is exactly like mapM , but accepts a lenticular (requires a traversal that includes lenses and primitives) over which you want a map .
traverseOf :: Functor f => Iso stab -> (a -> fb) -> s -> ft traverseOf :: Functor f => Lens stab -> (a -> fb) -> s -> ft traverseOf :: Applicative f => Traversal stab -> (a -> fb) -> s -> ft
So, for your example, you can simply use:
traverseOf (traverse._Foo._Moo._1._Item._1) (... expression of type String -> IO String ...) foos
There is also a version of the traverseOf operator called %%~ .
If you are a little familiar with the representation of lenses inside the lens library, you may notice that traverseOf = id ! So, with this knowledge, you can rewrite the example simply:
(traverse._Foo._Moo._1._Item._1) (... expression of type String -> IO String ...) foos
(You even used traverse , which is just mapM , to build a traversal! Lenses / primitives are similar to traverse , but more specific.)
But that's just aside, but you can use traverseOf for clarity.
source share