The problem is pretty simple. I have a structure that looks something like this
data Foo = Foo [Bar]
data Bar = Boo | Moo Item Int
data Item = Item String Int
and I have a lens for changing the contents of the Item
s inside the data structure, such as this
let foos = [Foo [Boo, Moo (Item "bar" 20) 10]]
over (traverse._Foo._Moo._1._Item._1) ("foo" ++) foos
-- which yields [Foo [Boo, Moo (Item "foobar" 20) 10]]
The structure here isn't important, I just wanted to show an example that uses prisms and something deeply nested.
Now the problem is that I need the function passed to over
to be String -> IO String
, instead of just String -> String
. A similar thing to what I'm looking for here is something like mapM
, but with lenses. Is it possible to do something like this?