1

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 Lenses. I'm also wondering why Array does not provide an instance for the At lens. Any pointer on it?

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Alright ! Makes sense for lens laws ! Didn´t got the hint from Pursuit

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.