Using 'lens' for "over"-like computation in Monad

30 Aug
2014
30 Aug
'14
3:44 a.m.
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.
3919
Age (days ago)
3919
Last active (days ago)
0 comments
1 participants
participants (1)
-
Nikolay Amiantov