
Thank you! I'm still lost in the forest of all lens functions and generality, and haven't expected this signature. Can someone recommend good reading on all the lens-related types and classes, what they represent and how can they be used? (interested not only in "how", but also "why") 30 авг. 2014 г. 11:20 пользователь "Benno Fünfstück" < benno.fuenfstueck@gmail.com> написал:
The lens operator that does this is %%~, also called `traverseOf`:
λ: ("Hello", "World") & _1 %%~ (\a -> putStrLn a >> return a) Hello ("Hello","World")
Also see the documentation: http://hackage.haskell.org/package/lens-4.4.0.1/docs/Control-Lens-Traversal....
-- Benno
2014-08-30 9:44 GMT+02:00 Nikolay Amiantov
: Hello Cafe,
I'm trying to wrap my head around 'lens' library. My current exercise is to modify something using Lens in monad. Say,
("Hello", "World") & _1 `myOp` (\a -> putStrLn a >> return a)
in IO, where myOp would be of type:
myOp :: Monad m => Lens s t a b -> (a -> m b) -> s -> m t
Of course I can write it myself, using combination of "view" and "set":
myOp lens f v = f (view lens v) >>= flip (set lens) v
(have not checked this, but something like that should do), but is there a more elegant way?
Nikolay.
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe