export and document lens-view*, lens-set*, and lens-transform*

This commit is contained in:
AlexKnauth 2015-07-07 10:23:53 -04:00
parent 660d2114b5
commit 0928cc068f
5 changed files with 54 additions and 4 deletions

View File

@ -3,7 +3,7 @@
(define collection 'multi)
(define version 0.2)
(define version "0.3")
(define deps

View File

@ -22,3 +22,14 @@
@lenses-examples[
(lens-transform first-lens number->string '(1 2 3))
]}
@defproc[(lens-transform* [target target/c] [lens lens?] [transformer (-> view/c view/c)] ... ...)
target/c]{
Like @racket[lens-transform], except that it can take multiple
lenses-transformer pairs in the same way as @racket[lens-set*], and
the argument order is switched in the same way.
@lenses-examples[
(lens-transform* '(1 2 3 4 5)
first-lens number->string
third-lens (λ (x) (* 100 x)))
]}

View File

@ -3,6 +3,8 @@
(require unstable/sequence
fancy-app
"base.rkt")
(module+ test
(require rackunit))
(provide lens-view
lens-set
@ -30,3 +32,20 @@
(for/fold ([v v]) ([lens/x (in-slice 2 lenses/xs)])
(match-define (list lens x) lens/x)
(lens-set lens v x)))
(module+ test
(define (set-first l v)
(list* v (rest l)))
(define (set-second l v)
(list* (first l) v (rest (rest l))))
(define first-lens (make-lens first set-first))
(define second-lens (make-lens second set-second))
(check-equal? (lens-view first-lens '(1 2 3)) 1)
(check-equal? (lens-set first-lens '(1 2 3) 'a) '(a 2 3))
(check-equal? (lens-view* '((1 2) 3) first-lens second-lens)
2)
(check-equal? (lens-set* '(1 2 3)
first-lens 10
second-lens 20)
'(10 20 3))
)

View File

@ -22,3 +22,26 @@
@lenses-examples[
(lens-set first-lens '(1 2 3) 'a)
]}
@defproc[(lens-view* [target target/c] [lens lens?] ...) view/c]{
Like @racket[lens-view], except that it can take multiple lenses,
which are combined into a nested lens. The argument order is
switched, so that the @racket[target] comes first and the
@racket[lens] arguments come after it.
@racket[(lens-view* target lens ...)] produces the same value as
@racket[(lens-view (lens-thrush lens ...) target)], but can be more
efficient.
@lenses-examples[
(lens-view* '(a b ((c d) e f) g) third-lens first-lens second-lens)
]}
@defproc[(lens-set* [target target/c] [lens lens?] [new-view view/c] ... ...) target/c]{
Like @racket[lens-set], except that it can take multiple
lenses-value pairs. Like @racket[lens-view*], the argument order is
switched, so that the @racket[target] comes first and the lens-value
pairs come after it. @racket[lens-set*] is analogous to @racket[hash-set*].
@lenses-examples[
(lens-set* '(1 2 3 4 5)
first-lens 10
third-lens 300)
]}

View File

@ -15,9 +15,6 @@
"syntax-keyword.rkt")
focus-lens
drop-lens
lens-set*
lens-transform*
lens-view*
list-ref-nested-lens
take-lens
use-applicable-lenses!))