lens-1.2: Lenses, Folds and Traversals

PortabilityMPTCs, Rank2Types, LiberalTypeSynonyms
Stabilityprovisional
MaintainerEdward Kmett <ekmett@gmail.com>
Safe HaskellSafe-Infered

Data.Array.Lens

Contents

Description

 

Synopsis

Indexing

ix :: (IArray a e, Ix i) => i -> Simple Lens (a i e) eSource

Access an element of an array.

Note: The indexed element is assumed to exist in the target array.

 arr ! i = arr^.ix i
 arr // [(i,e)] = ix i ^= e $ arr
 ghci> ix 2 ^= 9 $ listArray (1,5) [4,5,6,7,8]
 array (1,5) [4,9,6,7,8]

Setters

amapped :: (IArray a c, IArray a d, Ix i) => Setter (a i c) (a i d) c dSource

This setter can be used to map over all of the values in an array.

Note: traverseArray is strictly more general and permits more operations

 amap = adjust amapped
 amapped = sets amap

ixmapped :: (IArray a e, Ix i, Ix j) => (i, i) -> Setter (a j e) (a i e) i jSource

This setter can be used to derive a new array from an old array by applying a function to each of the indices.

 ixmap = adjust . ixmapped
 ixmapped = sets . ixmap

Traversal

traverseArray :: (IArray a c, IArray a d, Ix i) => Traversal (a i c) (a i d) c dSource

Generic Traversal of the elements of an array.

 amap = adjust traverseArray