Lens setter to add element to end of tuple

302 views Asked by At

Is there any lens that will help me do the following transformation for a tuple of any length (say up 10-15 elements, at least):

(a, b, c) -> d -> (a, b, c, d)
1

There are 1 answers

3
samsergey On

To get a lens you need a getter an setter functions. Unfortunately, there is no way to obtain a fourth element of a triple, (except for Nothing, or any other unit type). So, you end up with a bunch of setters, which are trivial pattern-matching functions (one for each n-tuple), but not a lens.

Probably, you need a simple list, or some free construction, if you really need non-uniform container?