rename list-compound-lens and hash-compound-lens to lens-join/...

This commit is contained in:
AlexKnauth 2015-07-14 23:48:31 -04:00
parent d05e344a24
commit 734bfbaa69
5 changed files with 27 additions and 27 deletions

View File

@ -10,14 +10,14 @@
(provide
(contract-out
[compound-list-lens (->* () #:rest (listof lens?) lens?)]
[compound-hash-lens (->* () #:rest (listof2 any/c lens?) lens?)]))
[lens-join/list (->* () #:rest (listof lens?) lens?)]
[lens-join/hash (->* () #:rest (listof2 any/c lens?) lens?)]))
(define (zip xs ys)
(append-map list xs ys))
(define (compound-list-lens . lenses)
(define (lens-join/list . lenses)
(define (get target)
(apply lens-view/list target lenses))
(define (set target new-views)
@ -27,16 +27,16 @@
(module+ test
(define first-third-fifth-lens
(compound-list-lens first-lens
third-lens
fifth-lens))
(lens-join/list first-lens
third-lens
fifth-lens))
(check-equal? (lens-view first-third-fifth-lens '(a b c d e f))
'(a c e))
(check-equal? (lens-set first-third-fifth-lens '(a b c d e f) '(1 2 3))
'(1 b 2 d 3 f)))
(define first-first-lens
(compound-list-lens first-lens
first-lens))
(lens-join/list first-lens
first-lens))
(define (value-list->hash keys vs)
@ -55,9 +55,9 @@
'((a b c) (1 2 3) (FOO BAR BAZ))))
(define (compound-hash-lens . keys/lenses)
(define (lens-join/hash . keys/lenses)
(match-define (list keys lenses) (split-slice 2 keys/lenses))
(define list-lens (apply compound-list-lens lenses))
(define list-lens (apply lens-join/list lenses))
(define (get target)
(value-list->hash keys (lens-view list-lens target)))
(define (set target new-view-hash)
@ -65,8 +65,8 @@
(make-lens get set))
(module+ test
(define a-b-lens (compound-hash-lens 'b third-lens
'a first-lens))
(define a-b-lens (lens-join/hash 'b third-lens
'a first-lens))
(check-equal? (lens-view a-b-lens '(1 2 3))
(hash 'a 1 'b 3))
(check-equal? (lens-set a-b-lens '(1 2 3) (hash 'a 100 'b 200))

View File

@ -3,11 +3,11 @@
@(require lens/doc-util/main)
@title{Compound Lenses}
@title{Joining Lenses}
@defmodule[unstable/lens/compound]
@defmodule[unstable/lens/join]
@defproc[(compound-list-lens [lens lens?] ...) lens?]{
@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
@ -15,22 +15,22 @@
setting the later lenses override the earlier ones.
@lenses-unstable-examples[
(define first-third-fifth-lens
(compound-list-lens first-lens
third-lens
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[(compound-hash-lens [key any/c] [lens lens?] ... ...) lens?]{
@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[compound-list-lens],
as the hash keys. In the same manner as @racket[lens-join/list],
if lenses share views later lenses take precedence when
setting.
@lenses-unstable-examples[
(define a-b-lens (compound-hash-lens 'a first-lens
'b third-lens))
(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

@ -1,7 +1,7 @@
#lang racket
(require lens
"compound.rkt")
"join.rkt")
(module+ test
(require rackunit))
@ -21,7 +21,7 @@
(define (list-refs-lens . indices)
(apply compound-list-lens (map list-ref-lens indices)))
(apply lens-join/list (map list-ref-lens indices)))
(module+ test
(define 1-5-6-lens (list-refs-lens 1 5 6))

View File

@ -1,7 +1,7 @@
#lang racket
(require "syntax.rkt"
"compound.rkt"
"join.rkt"
"list.rkt"
"hash.rkt"
"view-set.rkt"
@ -11,7 +11,7 @@
)
(provide (all-from-out "syntax.rkt"
"compound.rkt"
"join.rkt"
"list.rkt"
"hash.rkt"
"view-set.rkt"

View File

@ -10,7 +10,7 @@ may change in future releases. Do not depend on
this library being backwards-compatible.
@include-section["view-set.scrbl"]
@include-section["compound.scrbl"]
@include-section["join.scrbl"]
@include-section["list.scrbl"]
@include-section["hash.scrbl"]
@include-section["syntax.scrbl"]