provide and document transformer-lens

This commit is contained in:
AlexKnauth 2015-08-31 15:48:38 -04:00
parent dde85c9796
commit c9fa6fb8ea
3 changed files with 28 additions and 0 deletions

View File

@ -13,4 +13,5 @@
"struct-nested.rkt"
"sublist.rkt"
"syntax.rkt"
"transformer.rkt"
"view-set.rkt"

View File

@ -26,6 +26,7 @@ this library being backwards-compatible.
"struct-nested.scrbl"
"sublist.scrbl"
"syntax.scrbl"
"transformer.scrbl"
"view-set.scrbl"
)

View File

@ -0,0 +1,26 @@
#lang scribble/manual
@(require lens/private/doc-util/main)
@title{Lenses that transform subpieces}
@defmodule[unstable/lens/transformer]
@defproc[(transformer-lens [lens lens?] [transform-lens lens?]) lens?]{
Creates a lens that transforms the subpiece of the target that @racket[lens]
views with @racket[transform-lens].
@racketblock[(lens-view (transformer-lens lens transform-lens) target)]
is equivalent to:
@racketblock[(lens-transform lens target (λ (v) (lens-view transform-lens v)))]
@lens-unstable-examples[
(define first-sym->str
(transformer-lens first-lens symbol->string-lens))
(lens-view first-sym->str '(a b c))
(lens-set first-sym->str '(a b c) '("a" b c))
(lens-set first-sym->str '(a b c) '("z" b c))
(lens-set first-sym->str '(a b c) '("z" bee sea))
(lens-view first-sym->str (lens-set first-sym->str '(a b c) '("z" bee sea)))
]}