lens-1.4: Lenses, Folds and Traversals

Portability portable provisional Edward Kmett Safe-Infered

Data.List.Lens

Description

Traversals for manipulating parts of a list.

Synopsis

# Documentation

_head :: Simple Lens [a] aSource

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

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

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

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

``` ghci> _tail <~ [3,4,5] \$ [1,2]
[1,3,4,5]
```

_last :: Simple Lens [a] aSource

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

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

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

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

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

``` ghci> "abcde"^.interspersed ','
"a,b,c,d,e"
```
``` xs^.interspersed a = intersperse a xs
```

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

Obtain a version of the list with the supplied value intercalated

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

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

Traversal for editing the tail of a list.

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

Traverse all but the last element of a list

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

Traverse the last element in a list.

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