Portability | MPTCs, Rank2Types, LiberalTypeSynonyms |
---|---|
Stability | provisional |
Maintainer | Edward Kmett <ekmett@gmail.com> |
Safe Haskell | Safe-Infered |
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
>>>
ix 2 ^= 9 $ listArray (1,5) [4,5,6,7,8]
array (1,5) [4,9,6,7,8]
Setters
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.
This is a contravariant Setter
.
ixmap = adjust . ixmapped ixmapped = sets . ixmap
adjust (ixmapped b) f arr ! i = arr ! f i bounds (adjust (ixmapped b) f arr) = b
Traversal
traverseArray :: (IArray a c, IArray a d, Ix i) => IndexedTraversal i (a i c) (a i d) c dSource
Generic IndexedTraversal
of the elements of an array, using the index into the
array as the index of the traversal.
amap = adjust traverseArray