Reputation: 65
I'm trying to remove an element from an Array a
using the index of the element but I can't find a way to do it with Lens
es. I'm also wondering why Array
does not provide an instance for the At
lens. Any pointer on it?
Upvotes: 1
Views: 114
Reputation: 46228
I'm also wondering why Array does not provide an instance for the
At
lens.
You can look at the Control.Lens.At
module docs for a hint:
... not Array-like ones, where you cannot satisfy the Lens laws
One of the laws which breaks is set l v' (set l v s) ≡ set l v' s
. The reason being that deleting an index moves the other indices. So the following can't make sense:
myArray
& at 6 .~ Nothing
& at 6 .~ Just 10
I don't know of a way to have deleting array elements be Lens like.
Upvotes: 1