lens
lens copied to clipboard
struct->struct lens?
Something like this:
(struct foo (a b c))
(struct bar (x y z))
(define foo->bar-lens
(struct->struct-lens foo bar))
> (lens-view foo->bar-lens (foo 1 2 3))
(bar 1 2 3)
Or possibly something that would allow fields to change order?
(define foo->bar-lens2
(struct->struct-lens foo bar [a y] [b z] [c x]))
> (lens-view foo->bar-lens2 (foo 1 2 3))
(bar 3 1 2)
Or even something that would allow that other lenses in between?
(struct foo (a b c))
(struct bar (x y z))
(define foo->bar-lens3
(struct->struct-lens foo bar
[a first-lens y]
[b second-lens z]
[c third-lens x]))
> (lens-view foo->bar-lens3 (foo '(1 2 3) '(4 5 6) '(7 8 9)))
(bar 9 1 5)
The first two could be isomorphism-lenses as well, but the third one couldn't.
I think the third is easily defined in terms of lens-join/struct
, so I'm not sure that one's necessary. I definitely think it should possible to change the order of the fields.