lens - Monadic version of .~ (Haskell) -


I . I'm looking for a version of which takes a value wrapped in a monad, for example:

(0, 1) & amp; _1. ~ 100 = (100,1)

Fictional . ~~ was:

(0, 1) & amp; ; _1. ~ 100 Returns 100 = Return (100,1)

Although it will not be difficult to define, is this lens already defined in the package?

I do not know about an single operator, But with some "small" adjustments, it essentially adjusts what the raw application of the lens does:

  • You can only modify the function of the modified function Use.
  • Your monaad a function , as is almost all (it will be mandatory from GHC 7.10, but not yet in 7.8)

Then you can do this:

  prelude control. Lens & gt; (0,1) & amp; _1 (const (bus 100)) bus (100,1) offer control. Lens & gt; (0,1) & amp; _1 (const [100]) [(100,1)] Proposal control. Lens & gt; (0,1) & amp; _1 (const [100,200]) [(100,1), (200,1)]  

here also traversals :

 Works with  Prelude Control Lens & gt; (0,1) & amp; Both (const [100,200]) [(100,100), (100,200), (200,100), (200,200)]  

If you still want the operator, then %% ~ The operator is defined, but it is essentially a type-restricted option for id :

  prelude control. Lens & gt; (0,1) & amp; _1 %% ~ const (return 100): either () (int, int) right (100,1)  

Finally, although you done It's easy to say, your . ~~ operator (which I think would be logically .% ~ or it seems that it was actually in lens ) just as Must be defined

  prelude control. Lens & gt; Let's (. ~ ~) = (.nost) offer control. Lens & gt; (0,1) & amp; _1. ~ 100 Returns 100: either () (int, int) right (100,1)  

Comments