Skip to content

struct->struct lens? #267

@AlexKnauth

Description

@AlexKnauth

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions