Portability | portable |
---|---|

Stability | provisional |

Maintainer | Edward Kmett <ekmett@gmail.com> |

Safe Haskell | Safe-Infered |

Traversals for manipulating parts of a list.

- _head :: Simple Lens [a] a
- _tail :: Simple Lens [a] [a]
- _last :: Simple Lens [a] a
- _init :: Simple Lens [a] [a]
- interspersed :: a -> Getter [a] [a]
- intercalated :: [a] -> Getter [[a]] [a]
- traverseList :: IndexedTraversal Int [a] [b] a b
- traverseHead :: SimpleIndexedTraversal Int [a] a
- traverseTail :: SimpleIndexedTraversal Int [a] a
- traverseInit :: SimpleIndexedTraversal Int [a] a
- traverseLast :: SimpleIndexedTraversal Int [a] a

# Documentation

_head :: Simple Lens [a] aSource

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

`>>>`

1`[1,2,3]^._head`

_tail :: Simple Lens [a] [a]Source

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

`>>>`

[1,3,4,5]`_tail .~ [3,4,5] $ [1,2]`

_last :: Simple Lens [a] aSource

A lens reading and writing to the last element of a *non-empty* list

`>>>`

2`[1,2]^._last`

_init :: Simple Lens [a] [a]Source

A lens reading and replacing all but the a last element of a *non-empty* list

`>>>`

[1,2,3]`[1,2,3,4]^._init`

interspersed :: a -> Getter [a] [a]Source

Obtain a version of the list with the supplied value interspersed.

`>>>`

"a,b,c,d,e"`"abcde"^.interspersed ','`

xs^.interspersed a = intersperse a xs

intercalated :: [a] -> Getter [[a]] [a]Source

Obtain a version of the list with the supplied value intercalated

# Traversals

traverseList :: IndexedTraversal Int [a] [b] a bSource

Indexed traversal of a list. The position in the list is available as the index.

traverseHead :: SimpleIndexedTraversal Int [a] aSource

The traversal for reading and writing to the head of a list

The position of the head in the original list (0) is available as the index.

`>>>`

[2,2,3]`traverseHead +~ 1 $ [1,2,3]`

traverseHead :: Applicative f => (a -> f a) -> [a] -> f [a]

traverseTail :: SimpleIndexedTraversal Int [a] aSource

Traversal for editing the tail of a list.

The position of each element *in the original list* is available as the index.

`>>>`

[1,3,4]`traverseTail +~ 1 $ [1,2,3]`

traverseTail :: Applicative f => (a -> f a) -> [a] -> f [a]

traverseInit :: SimpleIndexedTraversal Int [a] aSource

Traverse all but the last element of a list

The position of each element is available as the index.

`>>>`

[2,3,3]`traverseInit +~ 1 $ [1,2,3]`

traverseInit :: Applicative f => (a -> f a) -> [a] -> f [a]

traverseLast :: SimpleIndexedTraversal Int [a] aSource

Traverse the last element in a list.

The position of the last element in the original list is available as the index.

`>>>`

[1,2,4]`traverseLast +~ 1 $ [1,2,3]`

traverseLast :: Applicative f => (a -> f a) -> [a] -> f [a]