diff --git a/unstable/lens/hash-pluck.rkt b/unstable/lens/hash-pick.rkt similarity index 61% rename from unstable/lens/hash-pluck.rkt rename to unstable/lens/hash-pick.rkt index 7fdd217..1c96a87 100644 --- a/unstable/lens/hash-pluck.rkt +++ b/unstable/lens/hash-pick.rkt @@ -1,15 +1,16 @@ #lang racket/base -(provide hash-pluck-lens) +(provide hash-pick-lens) (require racket/list lens/base/main "hash.rkt" "join.rkt") + (module+ test (require rackunit)) -(define (hash-pluck-lens . ks) +(define (hash-pick-lens . ks) (apply lens-join/hash (append-map (λ (k) @@ -17,8 +18,8 @@ ks))) (module+ test - (check-equal? (lens-view (hash-pluck-lens 'a 'c) (hash 'a 1 'b 2 'c 3)) + (check-equal? (lens-view (hash-pick-lens 'a 'c) (hash 'a 1 'b 2 'c 3)) (hash 'a 1 'c 3)) - (check-equal? (lens-set (hash-pluck-lens 'a 'c) (hash 'a 1 'b 2 'c 3) (hash 'a 4 'c 5)) + (check-equal? (lens-set (hash-pick-lens 'a 'c) (hash 'a 1 'b 2 'c 3) (hash 'a 4 'c 5)) (hash 'a 4 'b 2 'c 5)) ) diff --git a/unstable/lens/hash-pluck.scrbl b/unstable/lens/hash-pick.scrbl similarity index 60% rename from unstable/lens/hash-pluck.scrbl rename to unstable/lens/hash-pick.scrbl index 07a4299..3881a69 100644 --- a/unstable/lens/hash-pluck.scrbl +++ b/unstable/lens/hash-pick.scrbl @@ -4,13 +4,13 @@ @title{Viewing a subset of a hash table by key} -@defmodule[unstable/lens/hash-pluck] +@defmodule[unstable/lens/hash-pick] -@defproc[(hash-pluck-lens [key any/c] ...) lens?]{ +@defproc[(hash-pick-lens [key any/c] ...) lens?]{ Creates a lens that views a subset of the target hash-table with the given @racket[key]s. The view, is another hash-table with only the given keys and their corrosponding values in the target hash-table. @lenses-unstable-examples[ - (lens-view (hash-pluck-lens 'a 'c) (hash 'a 1 'b 2 'c 3)) - (lens-set (hash-pluck-lens 'a 'c) (hash 'a 1 'b 2 'c 3) (hash 'a 4 'c 5)) + (lens-view (hash-pick-lens 'a 'c) (hash 'a 1 'b 2 'c 3)) + (lens-set (hash-pick-lens 'a 'c) (hash 'a 1 'b 2 'c 3) (hash 'a 4 'c 5)) ]} diff --git a/unstable/lens/main.rkt b/unstable/lens/main.rkt index d755f4d..24f04e7 100644 --- a/unstable/lens/main.rkt +++ b/unstable/lens/main.rkt @@ -10,7 +10,7 @@ "sublist.rkt" "struct.rkt" "arrow.rkt" - "hash-pluck.rkt" + "hash-pick.rkt" "stream.rkt" ) @@ -24,6 +24,6 @@ "sublist.rkt" "struct.rkt" "arrow.rkt" - "hash-pluck.rkt" + "hash-pick.rkt" "stream.rkt" )) diff --git a/unstable/lens/main.scrbl b/unstable/lens/main.scrbl index 33d10b2..2327b94 100644 --- a/unstable/lens/main.scrbl +++ b/unstable/lens/main.scrbl @@ -19,5 +19,5 @@ this library being backwards-compatible. @include-section["sublist.scrbl"] @include-section["struct.scrbl"] @include-section["arrow.scrbl"] -@include-section["hash-pluck.scrbl"] +@include-section["hash-pick.scrbl"] @include-section["stream.scrbl"] diff --git a/unstable/lens/string.rkt b/unstable/lens/string.rkt index 31ca9ec..14fe9f5 100644 --- a/unstable/lens/string.rkt +++ b/unstable/lens/string.rkt @@ -1,16 +1,16 @@ #lang racket/base (provide string-ref-lens - string-pluck-lens - ) + string-pick-lens) (require fancy-app lens/base/main - "join.rkt" - ) + "join.rkt") + (module+ test (require rackunit)) + (define (string-ref-lens i) (make-lens (string-ref _ i) @@ -24,20 +24,17 @@ c (string-ref s j)))))) -(define (string-pluck-lens . is) +(module+ test + (check-equal? (lens-view (string-ref-lens 2) "abc") #\c) + (check-equal? (lens-set (string-ref-lens 0) "abc" #\A) "Abc")) + + +(define (string-pick-lens . is) (apply lens-join/string (map string-ref-lens is))) - (module+ test - (check-equal? (lens-view (string-ref-lens 0) "abc") #\a) - (check-equal? (lens-view (string-ref-lens 1) "abc") #\b) - (check-equal? (lens-view (string-ref-lens 2) "abc") #\c) - (check-equal? (lens-set (string-ref-lens 0) "abc" #\A) "Abc") - (check-equal? (lens-set (string-ref-lens 1) "abc" #\B) "aBc") - (check-equal? (lens-set (string-ref-lens 2) "abc" #\C) "abC") - (define 1-5-6-lens (string-pluck-lens 1 5 6)) + (define 1-5-6-lens (string-pick-lens 1 5 6)) (check-equal? (lens-view 1-5-6-lens "abcdefg") "bfg") (check-equal? (lens-set 1-5-6-lens "abcdefg" "BFG") - "aBcdeFG") - ) + "aBcdeFG")) diff --git a/unstable/lens/string.scrbl b/unstable/lens/string.scrbl index fafaac3..e976ef2 100644 --- a/unstable/lens/string.scrbl +++ b/unstable/lens/string.scrbl @@ -11,11 +11,11 @@ Returns a lens for viewing the @racket[i]th character of a string. (lens-set (string-ref-lens 2) "abcdef" #\C) ]} -@defproc[(string-pluck-lens [i exact-nonnegative-integer?]) lens?]{ +@defproc[(string-pick-lens [i exact-nonnegative-integer?]) lens?]{ Like @racket[list-refs-lens], but for strings. Equivalent to @racket[(lens-join/string (string-ref-lens i) ...)]. @lenses-unstable-examples[ - (define 1-5-6-lens (string-pluck-lens 1 5 6)) + (define 1-5-6-lens (string-pick-lens 1 5 6)) (lens-view 1-5-6-lens "abcdefg") (lens-set 1-5-6-lens "abcdefg" "BFG") ]} diff --git a/unstable/lens/vector.rkt b/unstable/lens/vector.rkt index 7eefbd6..eb88629 100644 --- a/unstable/lens/vector.rkt +++ b/unstable/lens/vector.rkt @@ -2,17 +2,17 @@ (provide vector-ref-lens vector-ref-nested-lens - vector-pluck-lens - ) + vector-pick-lens) (require fancy-app lens/base/main "arrow.rkt" - "join.rkt" - ) + "join.rkt") + (module+ test (require rackunit)) + (define (vector-ref-lens i) (make-lens (vector-ref _ i) @@ -26,25 +26,27 @@ x (vector-ref v j)))))) +(module+ test + (check-equal? (lens-view (vector-ref-lens 0) #(a b c)) 'a) + (check-equal? (lens-set (vector-ref-lens 2) #(a b c) "C") #(a b "C"))) + + (define (vector-ref-nested-lens . is) (apply lens-thrush (map vector-ref-lens is))) -(define (vector-pluck-lens . is) +(module+ test + (check-equal? (lens-transform (vector-ref-nested-lens 2 1) + #(a #(b c) #(d e f)) + symbol->string) + #(a #(b c) #(d "e" f)))) + + +(define (vector-pick-lens . is) (apply lens-join/vector (map vector-ref-lens is))) - (module+ test - (check-equal? (lens-view (vector-ref-lens 0) #(a b c)) 'a) - (check-equal? (lens-view (vector-ref-lens 1) #(a b c)) 'b) - (check-equal? (lens-view (vector-ref-lens 2) #(a b c)) 'c) - (check-equal? (lens-set (vector-ref-lens 0) #(a b c) "A") #("A" b c)) - (check-equal? (lens-set (vector-ref-lens 1) #(a b c) "B") #(a "B" c)) - (check-equal? (lens-set (vector-ref-lens 2) #(a b c) "C") #(a b "C")) - (check-equal? (lens-transform (vector-ref-nested-lens 2 1) #(a #(b c) #(d e f)) symbol->string) - #(a #(b c) #(d "e" f))) - (define 1-5-6-lens (vector-pluck-lens 1 5 6)) + (define 1-5-6-lens (vector-pick-lens 1 5 6)) (check-equal? (lens-view 1-5-6-lens #(a b c d e f g)) #(b f g)) (check-equal? (lens-set 1-5-6-lens #(a b c d e f g) #(1 2 3)) - #(a 1 c d e 2 3)) - ) + #(a 1 c d e 2 3))) diff --git a/unstable/lens/vector.scrbl b/unstable/lens/vector.scrbl index 7edabd4..4ed69b7 100644 --- a/unstable/lens/vector.scrbl +++ b/unstable/lens/vector.scrbl @@ -19,11 +19,11 @@ Equivalent to @racket[(lens-thrush (vector-ref-lens i) ...)]. (lens-set (vector-ref-nested-lens 2 1) #(a b #(s i) d) "eye") ]} -@defproc[(vector-pluck-lens [i exact-nonnegative-integer?] ...) lens?]{ +@defproc[(vector-pick-lens [i exact-nonnegative-integer?] ...) lens?]{ Like @racket[list-refs-lens], but for vectors. Equivalent to @racket[(lens-join/vector (vector-ref-lens i) ...)]. @lenses-unstable-examples[ - (define 1-5-6-lens (vector-pluck-lens 1 5 6)) + (define 1-5-6-lens (vector-pick-lens 1 5 6)) (lens-view 1-5-6-lens #(a b c d e f g)) (lens-set 1-5-6-lens #(a b c d e f g) #(1 2 3)) ]}