~ package:diagrams-lib

Create a linear trail between two given points.
twiddleEx
= mconcat ((~~) <$> hexagon 1 <*> hexagon 1)
# centerXY # pad 1.1
A version of (%%~) that works on ALens.
>>> ("hello","world") & _2 #%%~ \x -> (length x, x ++ "!")
(5,("hello","world!"))
A version of (%~) that works on ALens.
>>> ("hello","world") & _2 #%~ length
("hello",5)
A version of (.~) that works on ALens.
>>> ("hello","there") & _2 #~ "world"
("hello","world")
Adjust every target of an IndexedSetter, IndexedLens or IndexedTraversal with access to the index.
(%@~) ≡ iover
When you do not need access to the index then (%~) is more liberal in what it can accept.
l %~ f ≡ l %@~ const f
(%@~) :: IndexedSetter i s t a b    -> (i -> a -> b) -> s -> t
(%@~) :: IndexedLens i s t a b      -> (i -> a -> b) -> s -> t
(%@~) :: IndexedTraversal i s t a b -> (i -> a -> b) -> s -> t
Modifies the target of a Lens or all of the targets of a Setter or Traversal with a user supplied function. This is an infix version of over.
fmap f ≡ mapped %~ f
fmapDefault f ≡ traverse %~ f
>>> (a,b,c) & _3 %~ f
(a,b,f c)
>>> (a,b) & both %~ f
(f a,f b)
>>> _2 %~ length $ (1,"hello")
(1,5)
>>> traverse %~ f $ [a,b,c]
[f a,f b,f c]
>>> traverse %~ even $ [1,2,3]
[False,True,False]
>>> traverse.traverse %~ length $ [["hello","world"],["!!!"]]
[[5,5],[3]]
(%~) :: Setter s t a b    -> (a -> b) -> s -> t
(%~) :: Iso s t a b       -> (a -> b) -> s -> t
(%~) :: Lens s t a b      -> (a -> b) -> s -> t
(%~) :: Traversal s t a b -> (a -> b) -> s -> t
Logically && the target(s) of a Bool-valued Lens or Setter.
>>> both &&~ True $ (False, True)
(False,True)
>>> both &&~ False $ (False, True)
(False,False)
(&&~) :: Setter' s Bool    -> Bool -> s -> s
(&&~) :: Iso' s Bool       -> Bool -> s -> s
(&&~) :: Lens' s Bool      -> Bool -> s -> s
(&&~) :: Traversal' s Bool -> Bool -> s -> s
This can be used to chain lens operations using op= syntax rather than op~ syntax for simple non-type-changing cases.
>>> (10,20) & _1 .~ 30 & _2 .~ 40
(30,40)
>>> (10,20) &~ do _1 .= 30; _2 .= 40
(30,40)
This does not support type-changing assignment, e.g.
>>> (10,20) & _1 .~ "hello"
("hello",20)
Raise the target(s) of a floating-point valued Lens, Setter or Traversal to an arbitrary power.
>>> (a,b) & _1 **~ c
(a**c,b)
>>> (a,b) & both **~ c
(a**c,b**c)
>>> _2 **~ 10 $ (3,2)
(3,1024.0)
(**~) :: Floating a => Setter' s a    -> a -> s -> s
(**~) :: Floating a => Iso' s a       -> a -> s -> s
(**~) :: Floating a => Lens' s a      -> a -> s -> s
(**~) :: Floating a => Traversal' s a -> a -> s -> s
Multiply the target(s) of a numerically valued Lens, Iso, Setter or Traversal.
>>> (a,b) & _1 *~ c
(a * c,b)
>>> (a,b) & both *~ c
(a * c,b * c)
>>> (1,2) & _2 *~ 4
(1,8)
>>> Just 24 & mapped *~ 2
Just 48
(*~) :: Num a => Setter' s a    -> a -> s -> s
(*~) :: Num a => Iso' s a       -> a -> s -> s
(*~) :: Num a => Lens' s a      -> a -> s -> s
(*~) :: Num a => Traversal' s a -> a -> s -> s
Increment the target(s) of a numerically valued Lens, Setter or Traversal.
>>> (a,b) & _1 +~ c
(a + c,b)
>>> (a,b) & both +~ c
(a + c,b + c)
>>> (1,2) & _2 +~ 1
(1,3)
>>> [(a,b),(c,d)] & traverse.both +~ e
[(a + e,b + e),(c + e,d + e)]
(+~) :: Num a => Setter' s a    -> a -> s -> s
(+~) :: Num a => Iso' s a       -> a -> s -> s
(+~) :: Num a => Lens' s a      -> a -> s -> s
(+~) :: Num a => Traversal' s a -> a -> s -> s
Decrement the target(s) of a numerically valued Lens, Iso, Setter or Traversal.
>>> (a,b) & _1 -~ c
(a - c,b)
>>> (a,b) & both -~ c
(a - c,b - c)
>>> _1 -~ 2 $ (1,2)
(-1,2)
>>> mapped.mapped -~ 1 $ [[4,5],[6,7]]
[[3,4],[5,6]]
(-~) :: Num a => Setter' s a    -> a -> s -> s
(-~) :: Num a => Iso' s a       -> a -> s -> s
(-~) :: Num a => Lens' s a      -> a -> s -> s
(-~) :: Num a => Traversal' s a -> a -> s -> s
Replace every target of an IndexedSetter, IndexedLens or IndexedTraversal with access to the index.
(.@~) ≡ iset
When you do not need access to the index then (.~) is more liberal in what it can accept.
l .~ b ≡ l .@~ const b
(.@~) :: IndexedSetter i s t a b    -> (i -> b) -> s -> t
(.@~) :: IndexedLens i s t a b      -> (i -> b) -> s -> t
(.@~) :: IndexedTraversal i s t a b -> (i -> b) -> s -> t
Replace the target of a Lens or all of the targets of a Setter or Traversal with a constant value. This is an infix version of set, provided for consistency with (.=).
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
Divide the target(s) of a numerically valued Lens, Iso, Setter or Traversal.
>>> (a,b) & _1 //~ c
(a / c,b)
>>> (a,b) & both //~ c
(a / c,b / c)
>>> ("Hawaii",10) & _2 //~ 2
("Hawaii",5.0)
(//~) :: Fractional a => Setter' s a    -> a -> s -> s
(//~) :: Fractional a => Iso' s a       -> a -> s -> s
(//~) :: Fractional a => Lens' s a      -> a -> s -> s
(//~) :: Fractional a => Traversal' s a -> a -> s -> s
Propositional equality. If a :~: b is inhabited by some terminating value, then the type a is the same as the type b. To use this equality in practice, pattern-match on the a :~: b to get out the Refl constructor; in the body of the pattern-match, the compiler knows that a ~ b.
A version of (<%~) that works on ALens.
>>> ("hello","world") & _2 <#%~ length
(5,("hello",5))
A version of (<.~) that works on ALens.
>>> ("hello","there") & _2 <#~ "world"
("world",("hello","world"))
Adjust the target of an IndexedLens returning the intermediate result, or adjust all of the targets of an IndexedTraversal and return a monoidal summary along with the answer.
l <%~ f ≡ l <%@~ const f
When you do not need access to the index then (<%~) is more liberal in what it can accept. If you do not need the intermediate result, you can use (%@~) or even (%~).
(<%@~) ::             IndexedLens i s t a b      -> (i -> a -> b) -> s -> (b, t)
(<%@~) :: Monoid b => IndexedTraversal i s t a b -> (i -> a -> b) -> s -> (b, t)
Modify the target of a Lens and return the result. When you do not need the result of the operation, (%~) is more flexible.
(<%~) ::             Lens s t a b      -> (a -> b) -> s -> (b, t)
(<%~) ::             Iso s t a b       -> (a -> b) -> s -> (b, t)
(<%~) :: Monoid b => Traversal s t a b -> (a -> b) -> s -> (b, t)
Logically && a Boolean valued Lens and return the result. When you do not need the result of the operation, (&&~) is more flexible.
(<&&~) :: Lens' s Bool -> Bool -> s -> (Bool, s)
(<&&~) :: Iso' s Bool  -> Bool -> s -> (Bool, s)
Raise the target of a floating-point valued Lens to an arbitrary power and return the result. When you do not need the result of the operation, (**~) is more flexible.
(<**~) :: Floating a => Lens' s a -> a -> s -> (a, s)
(<**~) :: Floating a => Iso' s a  -> a -> s -> (a, s)
Multiply the target of a numerically valued Lens and return the result. When you do not need the result of the multiplication, (*~) is more flexible.
(<*~) :: Num a => Lens' s a -> a -> s -> (a, s)
(<*~) :: Num a => Iso'  s a -> a -> s -> (a, s)
Increment the target of a numerically valued Lens and return the result. When you do not need the result of the addition, (+~) is more flexible.
(<+~) :: Num a => Lens' s a -> a -> s -> (a, s)
(<+~) :: Num a => Iso' s a  -> a -> s -> (a, s)
Decrement the target of a numerically valued Lens and return the result. When you do not need the result of the subtraction, (-~) is more flexible.
(<-~) :: Num a => Lens' s a -> a -> s -> (a, s)
(<-~) :: Num a => Iso' s a  -> a -> s -> (a, s)