{"size": 888, "ext": "scrbl", "max_stars_repo_path": "lens-doc/unstable/lens/match.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/match.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/match.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": 40.3636363636, "max_line_length": 84, "alphanum_fraction": 0.6509009009}
#lang scribble/manual

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

@title{Lenses based on match patterns}

@defform[(match-lens id pattern replacement)]{
Creates a lens for viewing the @racket[id] within the @racket[pattern].

The @racket[replacement] expression should be an expression such that
@racket[(match target [pattern replacement])] produces a value equivalent to
@racket[target], and should use @racket[id] as the view.
@lens-unstable-examples[
  (define car-lens (match-lens a (cons a b) (cons a b)))
  (define cdr-lens (match-lens b (cons a b) (cons a b)))
  (define third-lens (match-lens c (list a b c d ...) (list* a b c d)))
  (define vector-second-lens (match-lens b (vector a b c ...) (apply vector a b c)))
  (define v2-of-l3-lens (match-lens d
                          (list a b (vector c d e ...) f ...)
                          (list* a b (apply vector c d e) f)))
]}
