Split and fix some docs

This commit is contained in:
Jack Firth 2015-08-18 15:59:10 -07:00
parent baebbe1da7
commit 11fc744bfe
14 changed files with 107 additions and 88 deletions

View File

@ -7,4 +7,3 @@
@include-section["laws.scrbl"] @include-section["laws.scrbl"]
@include-section["transform.scrbl"] @include-section["transform.scrbl"]
@include-section["contract.scrbl"] @include-section["contract.scrbl"]
@include-section["compose.scrbl"]

View File

@ -3,8 +3,6 @@
@(require "../doc-util/main.rkt") @(require "../doc-util/main.rkt")
@title{Composing Lenses}
@defproc[(lens-compose [lens lens?] ...) lens?]{ @defproc[(lens-compose [lens lens?] ...) lens?]{
Composes the given lenses together into one @italic{compound lens}. Composes the given lenses together into one @italic{compound lens}.
The compound lens operates similarly to composed functions do in The compound lens operates similarly to composed functions do in
@ -18,16 +16,6 @@
(lens-set first-of-second-lens '((1 a) (2 b) (3 c)) 200) (lens-set first-of-second-lens '((1 a) (2 b) (3 c)) 200)
]} ]}
@defproc[(lens-thrush [lens lens?] ...) lens?]{
Like @racket[lens-compose], but each @racket[lens] is combined in the
opposite order. That is, the first @racket[lens] is the first
@racket[lens] that the compound lenss target is viewed through.
@lenses-examples[
(define first-of-second-lens (lens-thrush second-lens first-lens))
(lens-view first-of-second-lens '((1 a) (2 b) (3 c)))
(lens-set first-of-second-lens '((1 a) (2 b) (3 c)) 200)
]}
@defthing[identity-lens lens?]{ @defthing[identity-lens lens?]{
The identity lens. Performs no destructuring at all - it's view is The identity lens. Performs no destructuring at all - it's view is
the target itself. For all lenses, both the target itself. For all lenses, both

View File

@ -0,0 +1,17 @@
#lang scribble/manual
@(require "../doc-util/main.rkt")
@defproc[(lens-join/hash [key any/c] [lens lens?] ... ...) lens?]{
Constructs a lens that combines the view of each
@racket[lens] into a hash of views with @racket[key]s
as the hash keys. In the same manner as @racket[lens-join/list],
if lenses share views later lenses take precedence when
setting.
@lenses-examples[
(define a-b-lens (lens-join/hash 'a first-lens
'b third-lens))
(lens-view a-b-lens '(1 2 3))
(lens-set a-b-lens '(1 2 3) (hash 'a 100 'b 200))
]}

View File

@ -0,0 +1,18 @@
#lang scribble/manual
@(require "../doc-util/main.rkt")
@defproc[(lens-join/list [lens lens?] ...) lens?]{
Constructs a lens that combines the view of each
@racket[lens] into a list of views. This lens can
be used to view and set a list of values in a single
target. If any of the lenses share views, then when
setting the later lenses override the earlier ones.
@lenses-examples[
(define first-third-fifth-lens
(lens-join/list first-lens
third-lens
fifth-lens))
(lens-view first-third-fifth-lens '(a b c d e f))
(lens-set first-third-fifth-lens '(a b c d e f) '(1 2 3))
]}

View File

@ -0,0 +1,16 @@
#lang scribble/manual
@(require "../doc-util/main.rkt")
@defproc[(lens-join/string [lens lens?] ...) lens?]{
Like @racket[lens-join/list], except the view is a string, not a list.
Each @racket[lens] argument must return a @racket[char?] as a view.
@lenses-examples[
(define string-first-third-fifth-lens
(lens-join/string first-lens
third-lens
fifth-lens))
(lens-view string-first-third-fifth-lens '(#\a #\b #\c #\d #\e #\f))
(lens-set string-first-third-fifth-lens '(#\a #\b #\c #\d #\e #\f) "ACE")
]}

View File

@ -0,0 +1,15 @@
#lang scribble/manual
@(require "../doc-util/main.rkt")
@defproc[(lens-join/vector [lens lens?] ...) lens?]{
Like @racket[lens-join/list], except the view is a vector, not a list.
@lenses-examples[
(define vector-first-third-fifth-lens
(lens-join/vector first-lens
third-lens
fifth-lens))
(lens-view vector-first-third-fifth-lens '(a b c d e f))
(lens-set vector-first-third-fifth-lens '(a b c d e f) #(1 2 3))
]}

View File

@ -1,57 +0,0 @@
#lang scribble/manual
@(require "doc-util/main.rkt")
@title{Joining Lenses}
@defproc[(lens-join/list [lens lens?] ...) lens?]{
Constructs a lens that combines the view of each
@racket[lens] into a list of views. This lens can
be used to view and set a list of values in a single
target. If any of the lenses share views, then when
setting the later lenses override the earlier ones.
@lenses-examples[
(define first-third-fifth-lens
(lens-join/list first-lens
third-lens
fifth-lens))
(lens-view first-third-fifth-lens '(a b c d e f))
(lens-set first-third-fifth-lens '(a b c d e f) '(1 2 3))
]}
@defproc[(lens-join/hash [key any/c] [lens lens?] ... ...) lens?]{
Constructs a lens that combines the view of each
@racket[lens] into a hash of views with @racket[key]s
as the hash keys. In the same manner as @racket[lens-join/list],
if lenses share views later lenses take precedence when
setting.
@lenses-examples[
(define a-b-lens (lens-join/hash 'a first-lens
'b third-lens))
(lens-view a-b-lens '(1 2 3))
(lens-set a-b-lens '(1 2 3) (hash 'a 100 'b 200))
]}
@defproc[(lens-join/vector [lens lens?] ...) lens?]{
Like @racket[lens-join/list], except the view is a vector, not a list.
@lenses-examples[
(define vector-first-third-fifth-lens
(lens-join/vector first-lens
third-lens
fifth-lens))
(lens-view vector-first-third-fifth-lens '(a b c d e f))
(lens-set vector-first-third-fifth-lens '(a b c d e f) #(1 2 3))
]}
@defproc[(lens-join/string [lens lens?] ...) lens?]{
Like @racket[lens-join/list], except the view is a string, not a list.
Each @racket[lens] argument must return a @racket[char?] as a view.
@lenses-examples[
(define string-first-third-fifth-lens
(lens-join/string first-lens
third-lens
fifth-lens))
(lens-view string-first-third-fifth-lens '(#\a #\b #\c #\d #\e #\f))
(lens-set string-first-third-fifth-lens '(#\a #\b #\c #\d #\e #\f) "ACE")
]}

11
lens/compound/main.scrbl Normal file
View File

@ -0,0 +1,11 @@
#lang scribble/manual
@title{Joining and Composing Lenses}
@include-section["compose.scrbl"]
@include-section["thrush.scrbl"]
@include-section["join-list.scrbl"]
@include-section["join-hash.scrbl"]
@include-section["join-vector.scrbl"]
@include-section["join-string.scrbl"]

View File

@ -0,0 +1,14 @@
#lang scribble/manual
@(require "../doc-util/main.rkt")
@defproc[(lens-thrush [lens lens?] ...) lens?]{
Like @racket[lens-compose], but each @racket[lens] is combined in the
opposite order. That is, the first @racket[lens] is the first
@racket[lens] that the compound lenss target is viewed through.
@lenses-examples[
(define first-of-second-lens (lens-thrush second-lens first-lens))
(lens-view first-of-second-lens '((1 a) (2 b) (3 c)))
(lens-set first-of-second-lens '((1 a) (2 b) (3 c)) 200)
]}

View File

@ -8,28 +8,23 @@
racket/base racket/base
racket/list racket/list
racket/stream racket/stream
racket/contract racket/contract)
)
(for-syntax racket/base (for-syntax racket/base
syntax/parse syntax/parse
racket/syntax racket/syntax))
))
(provide (all-from-out (provide (all-from-out
syntax/parse/define syntax/parse/define
"deflenses.rkt" "deflenses.rkt"
"lenses-examples.rkt" "lenses-examples.rkt")
)
(for-label (all-from-out (for-label (all-from-out
lens lens
unstable/lens unstable/lens
racket/base racket/base
racket/list racket/list
racket/stream racket/stream
racket/contract racket/contract))
))
(for-syntax (all-from-out (for-syntax (all-from-out
racket/base racket/base
syntax/parse syntax/parse
racket/syntax racket/syntax)))
)))

View File

@ -15,7 +15,8 @@ representation of getters and setters in object-oriented languages.
source code: @url["https://github.com/jackfirth/lens"] source code: @url["https://github.com/jackfirth/lens"]
@include-section["base/main.scrbl"] @include-section["base/main.scrbl"]
@include-section["compound/main.scrbl"]
@include-section["list/main.scrbl"] @include-section["list/main.scrbl"]
@include-section["struct.scrbl"] @include-section["struct/main.scrbl"]
@include-section["dict.scrbl"] @include-section["dict.scrbl"]
@include-section["applicable.scrbl"] @include-section["applicable.scrbl"]

View File

@ -1,10 +1,8 @@
#lang scribble/manual #lang scribble/manual
@(require "doc-util/main.rkt") @(require "../doc-util/main.rkt")
@title{Struct lenses}
@defform[(struct-lens struct-id field-id)]{ @defform[(struct-lens struct-id field-id)]{
Returns a lens for viewing the @racket[field-id] field of Returns a lens for viewing the @racket[field-id] field of
a @racket[struct-id] instance. a @racket[struct-id] instance.

6
lens/struct/main.scrbl Normal file
View File

@ -0,0 +1,6 @@
#lang scribble/manual
@title{Struct Lenses}
@include-section["field.scrbl"]
@include-section["struct.scrbl"]

View File

@ -1,13 +1,11 @@
#lang scribble/manual #lang scribble/manual
@(require lens/doc-util/main) @(require "../doc-util/main.rkt")
@title{Defining struct lenses automatically}
@defmodule[unstable/lens/struct] @defmodule[unstable/lens/struct]
@defform[(define-struct-lenses struct-id)]{ @defform[(define-struct-lenses struct-id)]{
Given a @racket[struct-id], defines lenses for the fields. Given a @racket[struct-id], defines a lens for each of its fields.
@lenses-unstable-examples[ @lenses-unstable-examples[
(struct foo (a b c) #:transparent) (struct foo (a b c) #:transparent)
(define-struct-lenses foo) (define-struct-lenses foo)