{"size": 1450, "ext": "scrbl", "max_stars_repo_path": "lens-doc/lens/private/base/base.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/lens/private/base/base.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/lens/private/base/base.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": 35.3658536585, "max_line_length": 73, "alphanum_fraction": 0.6751724138}
#lang scribble/manual

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

@title{Lens Construction}

@defproc[(lens? [v any/c]) boolean?]{
  Predicate for lenses.
}

@defproc[(make-lens [getter (-> target/c view/c)]
                    [setter (-> target/c view/c target/c)])
         lens?]{
  Given a getter and a setter, constructs a lens defined on values
  satisfying @racket[target/c] and viewing values satisfying
  @racket[view/c]. The getter must accept a target and return the
  lens's view. The setter must accept a target and a new view, and
  return a new target with its view replaced with the new view.
  @lens-examples[
    (define (set-first lst v)
      (list* v (rest lst)))
    (set-first '(1 2 3) 'a)
    (define first-lens (make-lens first set-first))
    (lens-view first-lens '(1 2 3))
    (lens-set first-lens '(1 2 3) 'a)
]}

@defform[(let-lens (view-id context-id) lens-expr target-expr body ...)]{
  Given a lens and a target, constructs the @italic{view} and the
  @italic{context} of the target through the lens and binds them
  to @racket[view-id] and @racket[context-id] respectively. The
  @italic{context} is a function that accepts a new view and sets
  the target's view to the new view. The context is conceptually
  a function representing the "hole" formed by abstracting the view
  of the target.
  @lens-examples[
    (let-lens (view context) first-lens '(1 2 3)
      (printf "View is ~a\n" view)
      (context 'a))
]}
