lens-3.7.1.2: Lenses, Folds and Traversals

Portability non-portable provisional Edward Kmett Trustworthy

Data.Vector.Lens

Description

This module provides lenses and traversals for working with generic vectors.

Synopsis

# Documentation

toVectorOf :: Getting (Endo [a]) s t a b -> s -> Vector aSource

Similar to toListOf, but returning a Vector.

# Isomorphisms

vector :: Iso [a] [b] (Vector a) (Vector b)Source

Convert a list to a Vector (or back)

reversed :: Iso (Vector a) (Vector b) (Vector a) (Vector b)Source

Convert a Vector to a version with all the elements in the reverse order

forced :: Iso (Vector a) (Vector b) (Vector a) (Vector b)Source

Convert a Vector to a version that doesn't retain any extra memory.

# Lenses

_head :: SimpleLens (Vector a) aSource

A lens reading and writing to the head of a non-empty Vector

Attempting to read or write to the head of an empty Vector will result in an error.

1

_tail :: SimpleLens (Vector a) (Vector a)Source

A lens reading and writing to the tail of a non-empty Vector

Attempting to read or write to the tail of an empty Vector will result in an error.

>>> _tail .~ Vector.fromList [3,4,5] \$ Vector.fromList [1,2]
fromList [1,3,4,5]

_last :: SimpleLens (Vector a) aSource

A Lens reading and writing to the last element of a non-empty Vector

Attempting to read or write to the last element of an empty Vector will result in an error.

>>> Vector.fromList [1,2]^._last
2

_init :: SimpleLens (Vector a) (Vector a)Source

A Lens reading and replacing all but the a last element of a non-empty Vector

Attempting to read or write to all but the last element of an empty Vector will result in an error.

>>> Vector.fromList [1,2,3,4]^._init
fromList [1,2,3]

Arguments

 :: Int i starting index -> Int n length -> SimpleLens (Vector a) (Vector a)

sliced i n provides a lens that edits the n elements starting at index i from a lens.

This is only a valid lens if you do not change the length of the resulting Vector.

Attempting to return a longer or shorter vector will result in violations of the Lens laws.

# Traversal of individual indices

This is a more efficient version of element that works for any Vector.

ordinal n is only a valid Lens into a Vector with length at least n + 1.

ordinals :: [Int] -> SimpleIndexedTraversal Int (Vector a) aSource

This Traversal will ignore any duplicates in the supplied list of indices.

>>> toListOf (ordinals [1,3,2,5,9,10]) \$ Vector.fromList [2,4..40]
[4,8,6,12,20,22]