Adjust lens-transform to play nicely with currying
This commit is contained in:
parent
6e26e1703a
commit
2c518f970c
|
@ -55,12 +55,12 @@
|
||||||
|
|
||||||
;; Composing a lens with a function to make a value-sensitive setter
|
;; Composing a lens with a function to make a value-sensitive setter
|
||||||
|
|
||||||
(define (lens-transform lens v f)
|
(define (lens-transform lens f v)
|
||||||
(let-lens (view setter) (lens v)
|
(let-lens (view setter) (lens v)
|
||||||
(setter (f view))))
|
(setter (f view))))
|
||||||
|
|
||||||
(module+ test
|
(module+ test
|
||||||
(check-equal? (lens-transform second-lens '(1 2 3) number->string) '(1 "2" 3)))
|
(check-equal? (lens-transform second-lens number->string '(1 2 3)) '(1 "2" 3)))
|
||||||
|
|
||||||
;; Lens composition
|
;; Lens composition
|
||||||
|
|
||||||
|
|
|
@ -77,8 +77,8 @@ source code: @url["https://github.com/jackfirth/lenses"]
|
||||||
]}
|
]}
|
||||||
|
|
||||||
@defproc[(lens-transform [lens (lens/c target/c view/c)]
|
@defproc[(lens-transform [lens (lens/c target/c view/c)]
|
||||||
[target target/c]
|
[transformer (-> view/c view/c)]
|
||||||
[transformer (-> view/c view/c)])
|
[target target/c])
|
||||||
target/c]{
|
target/c]{
|
||||||
Transforms the view of @racket[target] through the given @racket[lens]
|
Transforms the view of @racket[target] through the given @racket[lens]
|
||||||
with the @racket[transformer] function. Equivalent to getting the
|
with the @racket[transformer] function. Equivalent to getting the
|
||||||
|
@ -87,7 +87,7 @@ source code: @url["https://github.com/jackfirth/lenses"]
|
||||||
to the return value of calling @racket[transformer] with the old
|
to the return value of calling @racket[transformer] with the old
|
||||||
view.
|
view.
|
||||||
@lenses-examples[
|
@lenses-examples[
|
||||||
(lens-transform first-lens '(1 2 3) number->string)
|
(lens-transform first-lens number->string '(1 2 3))
|
||||||
]}
|
]}
|
||||||
|
|
||||||
@defproc[(lens-compose [lens proc] ...+) proc?]{
|
@defproc[(lens-compose [lens proc] ...+) proc?]{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user