Copyright | (C) 2012-16 Edward Kmett |
---|---|
License | BSD-style (see the file LICENSE) |
Maintainer | Edward Kmett <ekmett@gmail.com> |
Stability | provisional |
Portability | Rank2Types |
Safe Haskell | Trustworthy |
Language | Haskell2010 |
One commonly asked question is: can we combine two lenses,
and
Lens
` a b
into
Lens
` a c
.
This is fair thing to ask, but such operation is unsound in general.
See
Lens
` a (b, c)
lensProduct
.
Synopsis
- lensProduct :: ALens' s a -> ALens' s b -> Lens' s (a, b)
- prismSum :: APrism s t a b -> APrism s t c d -> Prism s t ( Either a c) ( Either b d)
- adjoin :: Traversal' s a -> Traversal' s a -> Traversal' s a
Documentation
lensProduct :: ALens' s a -> ALens' s b -> Lens' s (a, b) Source #
A lens product. There is no law-abiding way to do this in general.
Result is only a valid
Lens
if the input lenses project disjoint parts of
the structure
s
. Otherwise "you get what you put in" law
view
l (set
l v s) ≡ v
is violated by
>>>
let badLens :: Lens' (Int, Char) (Int, Int); badLens = lensProduct _1 _1
>>>
view badLens (set badLens (1,2) (3,'x'))
(2,2)
but we should get
(1,2)
.
Are you looking for
alongside
?
prismSum :: APrism s t a b -> APrism s t c d -> Prism s t ( Either a c) ( Either b d) Source #
A dual of
lensProduct
: a prism sum.
The law
preview
l (review
l b) ≡Just
b
breaks with
>>>
let badPrism :: Prism' (Maybe Char) (Either Char Char); badPrism = prismSum _Just _Just
>>>
preview badPrism (review badPrism (Right 'x'))
Just (Left 'x')
We put in
Right
value, but get back
Left
.
Are you looking for
without
?
adjoin :: Traversal' s a -> Traversal' s a -> Traversal' s a Source #