Portability | portable |
---|---|
Stability | provisional |
Maintainer | Edward Kmett <ekmett@gmail.com> |
Safe Haskell | Safe-Inferred |
Traversals for manipulating parts of a list.
Partial Lenses
_head :: SimpleIndexedTraversal Int [a] aSource
_last :: SimpleIndexedTraversal Int [a] aSource
A Traversal
reading and writing to the last element of a non-empty list
>>>
[1,2,3]^?!_last
3
>>>
[]^?_last
Nothing
>>>
[1,2]^?_last
Just 2
>>>
[] & _last .~ 1
[]
>>>
[0] & _last .~ 2
[2]
>>>
[0,1] & _last .~ 2
[0,2]
_init :: Simple Traversal [a] [a]Source
A Traversal
reading and replacing all but the a last element of a non-empty list
>>>
[1,2,3,4]^?!_init
[1,2,3]
>>>
[1,2] & _init .~ [3,4,5]
[3,4,5,2]
>>>
[] & _init .~ [1,2]
[]
>>>
[1,2,3]^?_init
Just [1,2]
>>>
[1,2]^?!_init
[1]
>>>
"hello"^._init
"hell"
>>>
""^._init
""