short-vec-lens-0.1.0.0: Lenses and related functionality for the `short-vec` package.
Safe HaskellNone
LanguageHaskell2010

Data.Vec.Short.Lens

Description

Lenses and related optics for Vecs.

Synopsis

List-based lenses

list :: KnownNat n => Iso (Vec n a) (Vec n b) [a] [b] Source #

A list (of the right length) is isomorphic to a vector. The list-to-vector direction is partial.

Arity-based lenses

paired :: Iso (Vec 2 a) (Vec 2 b) (a, a) (b, b) Source #

A two-element vector is isomorphic to a pair.

List-like operators

Constructor views

The cons view

consed :: Iso (a, Vec n a) (b, Vec m b) (Vec (n + 1) a) (Vec (m + 1) b) Source #

An isomorphism with an element added at the beginning of a vector.

The snoc view

snoced :: Iso (Vec n a, a) (Vec m b, b) (Vec (n + 1) a) (Vec (m + 1) b) Source #

An isomorphism with an element added at the end of a vector.

Operator views

The append view

chopped :: KnownNat m => Iso (Vec (m + n) a) (Vec (o + p) b) (Vec m a, Vec n a) (Vec o b, Vec p b) Source #

An isomorphism with a split vector.

The concat view

subVecs :: (KnownNat m, (n * m) ~ nm, (p * o) ~ po) => Iso (Vec nm a) (Vec po b) (Vec n (Vec m a)) (Vec p (Vec o b)) Source #

A vector can be split (isomorphically) into a vector of vectors.

The reverse view

reversed :: Iso (Vec n a) (Vec m b) (Vec n a) (Vec m b) Source #

A vector is isomorphic to its reversal.

The transposition view

vtransposed :: (KnownNat m, KnownNat p) => Iso (Vec n (Vec m a)) (Vec p (Vec o b)) (Vec m (Vec n a)) (Vec o (Vec p b)) Source #

Isomorphism of transposed vectors.

Misc lenses

midElem :: forall m n a b. Iso (Vec (n + 1) a) (Vec (m + 1) b) (a, Vec n a) (b, Vec m b) Source #

Isomorphism between a vector with and without its middle element.

ixElem :: forall n a b. Fin (n + 1) -> Iso (Vec (n + 1) a) (Vec (n + 1) b) (a, Vec n a) (b, Vec n b) Source #

Isomorphism between a vector with and without a single element at the given index.

ix :: Fin n -> Lens' (Vec n a) a Source #

Lens on a single element.

sliced :: forall m n a. (KnownNat m, KnownNat n, m <= n) => Fin ((n - m) + 1) -> Lens' (Vec n a) (Vec m a) Source #

A lens to a slice of the vector.

rotated :: forall n a b. Fin n -> Iso (Vec n a) (Vec n b) (Vec n a) (Vec n b) Source #

Isomorphism between a vector and a vector rotated i steps. The element at index 0 in the first vector is at index i in the second. E.g., view (rotated 1) (fromList ABCD) == fromList DABC

vdiagonal :: forall n a. KnownNat n => Lens' (Vec n (Vec n a)) (Vec n a) Source #

Lens on the main diagonal.