lens-2.1: Lenses, Folds and Traversals

Data.Complex.Lens

Description

Synopsis

real :: Simple Lens (Complex a) aSource

Access the realPart of a Complex number

realPart

Complex

real :: Functor f => (a -> f a) -> Complex a -> f (Complex a)

imaginary :: Simple Lens (Complex a) aSource

Access the imaginaryPart of a Complex number

imaginaryPart

imaginary :: Functor f => (a -> f a) -> Complex a -> f (Complex a)

polarize :: (RealFloat a, RealFloat b) => Iso (Complex a) (Complex b) (a, a) (b, b)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

traverseComplex :: Traversal (Complex a) (Complex b) a bSource

Traverse both the real and imaginary parts of a Complex number.

traverseComplex :: Applicative f => (a -> f b) -> Complex a -> f (Complex b)