This is similar to 'traverseOf2', just that the outer part is a monad.

Signed-off-by: Petr Pudlak <[email protected]>
---
 src/Ganeti/Lens.hs | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/Ganeti/Lens.hs b/src/Ganeti/Lens.hs
index 993bc7a..19abc87 100644
--- a/src/Ganeti/Lens.hs
+++ b/src/Ganeti/Lens.hs
@@ -31,10 +31,11 @@ module Ganeti.Lens
   , makeCustomLenses
   , makeCustomLenses'
   , traverseOf2
+  , mapMOf2
   , atSet
   ) where
 
-import Control.Applicative ((<$>))
+import Control.Applicative ((<$>), WrappedMonad(..))
 import Control.Lens
 import Control.Monad
 import Data.Functor.Compose (Compose(..))
@@ -76,6 +77,12 @@ traverseOf2 :: Over (->) (Compose f g) s t a b
             -> (a -> f (g b)) -> s -> f (g t)
 traverseOf2 k f = getCompose . traverseOf k (Compose . f)
 
+-- | Traverses over a composition of a monad and a functor.
+-- See 'traverseOf2'.
+mapMOf2 :: Over (->) (Compose (WrappedMonad m) g) s t a b
+        -> (a -> m (g b)) -> s -> m (g t)
+mapMOf2 k f = unwrapMonad . traverseOf2 k (WrapMonad . f)
+
 -- | A helper lens over sets.
 -- While a similar lens exists in the package (as @Lens' Set (Maybe ())@@),
 -- it's available only in most recent versions.
-- 
2.0.0.526.g5318336

Reply via email to