{"size": 1000, "ext": "scrbl", "max_stars_repo_path": "lens-doc/unstable/lens/struct-list.scrbl", "max_stars_repo_name": "AlexKnauth/lens", "max_stars_repo_stars_event_min_datetime": "2015-07-08T12:56:46.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T21:21:54.000Z", "max_issues_repo_path": "lens-doc/unstable/lens/struct-list.scrbl", "max_issues_repo_name": "AlexKnauth/lens", "max_issues_repo_issues_event_min_datetime": "2015-07-07T01:47:59.000Z", "max_issues_repo_issues_event_max_datetime": "2019-09-10T18:35:17.000Z", "max_forks_repo_path": "lens-doc/unstable/lens/struct-list.scrbl", "max_forks_repo_name": "AlexKnauth/lens", "max_forks_repo_forks_event_min_datetime": "2015-07-07T05:01:29.000Z", "max_forks_repo_forks_event_max_datetime": "2019-07-16T00:37:04.000Z"}
{"max_stars_count": 66, "max_issues_count": 199, "max_forks_count": 11, "avg_line_length": 32.2580645161, "max_line_length": 66, "alphanum_fraction": 0.665}
#lang scribble/manual

@(require lens/private/doc-util/main)

@title{Converting between structs and lists}

@deftogether[[
  @defform[(struct->list-lens struct-id)]
  @defform[(list->struct-lens struct-id)]]]{
Lenses that convert between structs and lists.

@lens-unstable-examples[
  (struct foo (a b c) #:transparent)
  (lens-view (struct->list-lens foo) (foo 1 2 3))
  (lens-set (struct->list-lens foo) (foo 1 2 3) '(4 5 6))
  (lens-view (list->struct-lens foo) '(1 2 3))
  (lens-set (list->struct-lens foo) '(1 2 3) (foo 4 5 6))
]

For structs that inherit from other structs, it puts the inherited
fields first, so that it matches the arguments to the constructor:

@lens-unstable-examples[
  (struct foo (a b c) #:transparent)
  (struct bar foo (d e))
  (lens-view (struct->list-lens bar) (bar 1 2 3 4 5))
  (lens-set (struct->list-lens bar) (bar 1 2 3 4 5) '(6 7 8 9 10))
  (lens-view (list->struct-lens bar) '(1 2 3 4 5))
  (lens-set (list->struct-lens bar) '(1 2 3 4 4) (bar 6 7 8 9 10))
]}
