f <$ a ≡ mapped .~ f $ a
>>> (a,b,c,d) & _4 .~ e (a,b,c,e)
>>> (42,"world") & _1 .~ "hello" ("hello","world")
>>> (a,b) & both .~ c (c,c)
(.~) :: Setter s t a b -> b -> s -> t (.~) :: Iso s t a b -> b -> s -> t (.~) :: Lens s t a b -> b -> s -> t (.~) :: Traversal s t a b -> b -> s -> t
x & myLens .~ ywould "set" a part of x :: b, specified by myLens :: Lens' a b, to a new value y :: a.
xVar & myLens .~~ yVarwould "set" a part of xVar :: BVar s b (a BVar holding a b), specified by myLens :: Lens' a b, to a new value given by yVar :: BVar s a. The result is a new (updated) value of type BVar s b. This is the main way to set values inside BVars of container types. Note that this does not incurr the performance overhead issues of viewVar and ^^., and is fairly cheap.
>>> (a,b) & _1 <.~ c (c,(c,b))
>>> ("good","morning","vietnam") & _3 <.~ "world" ("world",("good","morning","world"))
>>> (42,Map.fromList [("goodnight","gracie")]) & _2.at "hello" <.~ Just "world" (Just "world",(42,fromList [("goodnight","gracie"),("hello","world")]))
(<.~) :: Setter s t a b -> b -> s -> (b, t) (<.~) :: Iso s t a b -> b -> s -> (b, t) (<.~) :: Lens s t a b -> b -> s -> (b, t) (<.~) :: Traversal s t a b -> b -> s -> (b, t)
>>> _2 <.&.~ 7 $ ("hello",254) (6,("hello",6))
(<.&.~) :: Bits a => Iso s t a a -> a -> s -> (a, t) (<.&.~) :: Bits a => Lens s t a a -> a -> s -> (a, t) (<.&.~) :: (Bits a, Monoid a) => Traversal s t a a -> a -> s -> (a, t)
>>> _2 <.|.~ 6 $ ("hello",3) (7,("hello",7))
(<.|.~) :: Bits a => Iso s t a a -> a -> s -> (a, t) (<.|.~) :: Bits a => Lens s t a a -> a -> s -> (a, t) (<.|.~) :: (Bits a, Monoid a) => Traversal s t a a -> a -> s -> (a, t)
>>> _2 <<.&.~ 7 $ ("hello", 254) (254,("hello",6))
(<<.&.~) :: Bits a => Iso s t a a -> a -> s -> (a, t) (<<.&.~) :: Bits a => Lens s t a a -> a -> s -> (a, t) (<<.&.~) :: (Bits a, Monoid a) => Traversal s t a a -> a -> s -> (a, t)
>>> _2 <<.|.~ 6 $ ("hello", 3) (3,("hello",7))
(<<.|.~) :: Bits a => Iso s t a a -> a -> s -> (a, t) (<<.|.~) :: Bits a => Lens s t a a -> a -> s -> (a, t) (<<.|.~) :: (Bits a, Monoid a) => Traversal s t a a -> a -> s -> (a, t)