lens icon indicating copy to clipboard operation
lens copied to clipboard

add struct->struct-lens

Open AlexKnauth opened this issue 9 years ago • 2 comments

see https://github.com/jackfirth/lens/issues/267

AlexKnauth avatar Dec 11 '15 19:12 AlexKnauth

This is meant to be an isomorphism yes? I think allowing field reordering would be good. A contrived use case I can think of off the top of my head is wanting a lens to view a position struct in reverse order:

(struct position (x y))
(define inverse-pos-lens (struct->struct-lens position position [x y] [y x]))
(lens-view inverse-pos-lens (position 1 2))

jackfirth avatar Dec 11 '15 23:12 jackfirth

What you said in (https://github.com/jackfirth/lens/issues/267#issuecomment-163824481) about lens-join/struct made me think that of the cases where you might want to re-order the fields, a lot of those could be cases where you might want the freedom and power of (lens-join/struct position position-y-lens position-x-lens). I can see those use cases, but I can see many more where you might want (lens-join/struct position (lens-compose negate-lens position-y-lens) position-x-lens) or something similar.

AlexKnauth avatar Dec 12 '15 01:12 AlexKnauth