lens-3.7.1.2: Lenses, Folds and Traversals

Portability non-portable experimental Edward Kmett None

Data.Complex.Lens

Description

Lenses and traversals for complex numbers

Synopsis

# Documentation

Access the `realPart` of a `Complex` number

````>>> ````(a :+ b)^._realPart
```a
```
````>>> ````a :+ b & _realPart *~ 2
```a * 2 :+ b
```
``_realPart` :: `Functor` f => (a -> f a) -> `Complex` a -> f (`Complex` a)`

Access the `imagPart` of a `Complex` number

````>>> ````(a :+ b)^._imagPart
```b
```
````>>> ````a :+ b & _imagPart *~ 2
```a :+ b * 2
```
``_imagPart` :: `Functor` f => (a -> f a) -> `Complex` a -> f (`Complex` a)`

_polar :: 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`

law is violated when you set a `polar` value with 0 `magnitude` and non-zero `phase` as the `phase` information is lost, or with a negative `magnitude` which flips the `phase` and retains a positive `magnitude`. So don't do that!

Otherwise, this is a perfectly cromulent `Lens`.

_magnitude :: RealFloat a => Simple Lens (Complex a) aSource

Access the `magnitude` of a `Complex` number

````>>> ````(10.0 :+ 20.0) & _magnitude *~ 2
```20.0 :+ 40.0
```

This isn't quite a legal lens. Notably the

``view` l (`set` l b a) = b`

law is violated when you set a negative `magnitude`. This flips the `phase` and retains a positive `magnitude`. So don't do that!

Otherwise, this is a perfectly cromulent `Lens`.

Setting the `magnitude` of a zero `Complex` number assumes the `phase` is 0.

_phase :: RealFloat a => Simple Lens (Complex a) aSource

Access the `phase` of a `Complex` number

````>>> ````(mkPolar 10 (2-pi) & _phase +~ pi & view _phase) ≈ 2
```True
```

This isn't quite a legal lens. Notably the

``view` l (`set` l b a) = b`

law is violated when you set a `phase` outside the range `(-pi, pi]`. The phase is always in that range when queried. So don't do that!

Otherwise, this is a perfectly cromulent `Lens`.

_conjugate :: RealFloat a => Simple Iso (Complex a) (Complex a)Source

Access the `conjugate` of a `Complex` number

````>>> ````(2.0 :+ 3.0) & _conjugate . _imagPart -~ 1
```2.0 :+ 4.0
```
````>>> ````(mkPolar 10.0 2.0 ^. _conjugate . _phase) ≈ (-2.0)
```True
```

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

Traverse both the `realPart` and the `imagPart` of a `Complex` number.

````>>> ````a :+ b & complex .~ c
```c :+ c
```
````>>> ````a :+ b & complex *~ 2
```a * 2 :+ b * 2
```
````>>> ````sumOf complex (a :+ b)
```a + b
```
``complex` :: `Applicative` f => (a -> f b) -> `Complex` a -> f (`Complex` b)`