lens-3.6.0.3: Lenses, Folds and Traversals
Data.Complex.Lens
Description
Lenses and traversals for complex numbers
Synopsis
real :: Simple Lens (Complex a) aSource
Access the realPart of a Complex number
realPart
Complex
>>> (1.0 :+ 0.0)^.real 1.0
>>>
(1.0 :+ 0.0)^.real
>>> 3 :+ 1 & real *~ 2 6 :+ 1
3 :+ 1 & real *~ 2
real :: Functor f => (a -> f a) -> Complex a -> f (Complex a)
real
Functor
imaginary :: Simple Lens (Complex a) aSource
Access the imaginaryPart of a Complex number
imaginaryPart
>>> (0.0 :+ 1.0)^.imaginary 1.0
(0.0 :+ 1.0)^.imaginary
imaginary :: Functor f => (a -> f a) -> Complex a -> f (Complex a)
imaginary
polarize :: RealFloat a => Simple Iso (Complex a) (a, a)Source
This isn't quite a legal lens. Notably the
view l (set l b a) = b
view
set
law is violated when you set a polar value with 0 magnitude and non-zero phase as the phase information is lost. So don't do that!
polar
magnitude
phase
Otherwise, this is a perfectly cromulent Lens.
Lens
complex :: Traversal (Complex a) (Complex b) a bSource
Traverse both the real and imaginary parts of a Complex number.
>>> 0 & complex .~ 1 1 :+ 1
0 & complex .~ 1
>>> 3 :+ 4 & complex *~ 2 6 :+ 8
3 :+ 4 & complex *~ 2
>>> sumOf complex (1 :+ 2) 3
sumOf complex (1 :+ 2)
complex :: Applicative f => (a -> f b) -> Complex a -> f (Complex b)
complex
Applicative