I'm new to the excelent Control.Lens
and I'm trying to combine 2 lens in "parallel" (not in sequence) like I would do with `Control.Arrow.&&&).
If I take the example from the lens
documentation:
`data Foo a = Foo { _baz :: Int, _bar :: Int, a }
I would like to be able to do stuff like :
>> let foo = (bar &&& baz) .~ (1, 20) $ Foo undefined undefined "FOO"
>> foo ^. (bar &&& baz)
(1, 20)
I've looked everywhere and I could not find a way to do so. Is that because :
- (&&&) exist with another name and I missed it.
- It's useless. I should not need it, therefore nobody bothered implementing it.
- It's trivial to do in another way (using
both
or<*>
)
Update
&&&
can be implemented that way :
(/|\) :: Lens' f a -> Lens' f b -> Lens' f (a, b)
a /|\ b = lens getBoth setBoth where
getBoth f = (f ^. a, f ^. b)
setBoth f (v, w) = a .~ v $ f' where
f' = b .~ w $ f
barz :: Lens' Foo (Int, Int)
barz = bar /|\ baz
However, it needs a type signature which is a bit annoying.