class (MonadState s m, MonadState t n) => Zoom (m :: Type -> Type) (n :: Type -> Type) s t | m -> s, n -> t, m t -> n, n s -> m whereThis class allows us to zoom in, changing the State supplied by many
different monad transformers, potentially quite deep in a monad transformer
stack.
Its functions can be used to run a monadic action in a larger State than it
was defined in, using a Lens', an AffineTraversal' or a Traversal'.
This is commonly used to lift actions in a simpler State Monad into a
State Monad with a larger State type.
When used with a Traversal' over multiple values, the actions for each target are executed sequentially and the results are aggregated.
This can be used to edit pretty much any Monad transformer stack with a
State in it!
flip L.evalState ('a','b') $ zoom _1 $ use equality'a'
flip S.execState ('a','b') $ zoom _1 $ equality .= 'c'('c','b')
flip L.execState [(1,2),(3,4)] $ zoomMany traversed $ _2 %= (*10)[(1,20),(3,40)]
flip S.runState [('a',"b"),('c',"d")] $ zoomMany traversed $ _2 <%= (\x -> x <> x)("bbdd",[('a',"bb"),('c',"dd")])
flip S.evalState ("a","b") $ zoomMany each (use equality)"ab"
Instances10Zoom, …
Zoom m n s t => Zoom (MaybeT m) (MaybeT n) s tDefined in optics-extra-0.4.2.1 · Optics.ZoomMonad m => Zoom (StateT s m) (StateT t m) s tDefined in optics-extra-0.4.2.1 · Optics.ZoomMonad m => Zoom (StateT s m) (StateT t m) s tDefined in optics-extra-0.4.2.1 · Optics.ZoomZoom m n s t => Zoom (ExceptT e m) (ExceptT e n) s tDefined in optics-extra-0.4.2.1 · Optics.ZoomZoom m n s t => Zoom (IdentityT m) (IdentityT n) s tDefined in optics-extra-0.4.2.1 · Optics.ZoomZoom m n s t => Zoom (ReaderT e m) (ReaderT e n) s tDefined in optics-extra-0.4.2.1 · Optics.Zoom(Monoid w, Zoom m n s t) => Zoom (WriterT w m) (WriterT w n) s tDefined in optics-extra-0.4.2.1 · Optics.Zoom(Monoid w, Zoom m n s t) => Zoom (WriterT w m) (WriterT w n) s tDefined in optics-extra-0.4.2.1 · Optics.Zoom(Monoid w, Monad m) => Zoom (RWST r w s m) (RWST r w t m) s tDefined in optics-extra-0.4.2.1 · Optics.Zoom(Monoid w, Monad m) => Zoom (RWST r w s m) (RWST r w t m) s tDefined in optics-extra-0.4.2.1 · Optics.Zoom