How to modify using a monadic function with lenses?

自作多情 提交于 2019-11-30 17:52:47

in Control.Lens.Traversal:

traverseOf :: Over p f s t a b -> p a (f b) -> s -> f t
traverseOf = id

mapMOf :: Profunctor p =>
     Over p (WrappedMonad m) s t a b -> p a (m b) -> s -> m t
mapMOf l cmd = unwrapMonad #. l (WrapMonad #. cmd)

Example:

Prelude Control.Lens> traverseOf _1 (Just . (+2)) (2,2)
Just (4,2)

Prelude Control.Lens> mapMOf _1 (Just . (+2)) (2,2)
Just (4,2)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!