7.7
Lenses for Generic Collections
(require alexis/collection/lens) | |
package: alexis-collection-lens |
This provides lenses that examine and modify generic collections.
Constructs a lens for a keyed value of an indexable? instance.
Examples:
procedure
index : exact-nonnegative-integer?
Constructs a lens for a single element of a sequence?.
Constructs a lens that maps over sequence? instances.
Examples:
> (lens-view (map-lens (ref-lens 'key)) (list (hash 'key 1 'a 2) (hash 'key 2 'b 3))) #<stream>
> (sequence->list (lens-view (map-lens (ref-lens 'key)) (list (hash 'key 1 'a 2) (hash 'key 2 'b 3)))) '(1 2)
> (sequence->list (lens-set (map-lens (ref-lens 'key)) (list (hash 'key 1 'a 2) (hash 'key 2 'b 3)) (list 100 200))) '(#hash((a . 2) (key . 100)) #hash((b . 3) (key . 200)))
> (sequence->list (lens-transform (map-lens (ref-lens 'key)) (list (hash 'key 1 'a 2) (hash 'key 2 'b 3)) (λ (lst) (map (λ (x) (* 10 x)) lst)))) '(#hash((a . 2) (key . 10)) #hash((b . 3) (key . 20)))
value
A lens for the first element of a sequence?.
A lens for all but the first element of a sequence?.
procedure
n : exact-nonnegative-integer?
Constructs a lens for the first n elements of a
sequence?.
procedure
n : exact-nonnegative-integer?
Constructs a lens for the rest of a sequence? after the first
n elements.
procedure
(subsequence-lens start end) → lens?
start : exact-nonnegative-integer? end : exact-nonnegative-integer?
procedure
(subsequence*-lens start len) → lens?
start : exact-nonnegative-integer? len : exact-nonnegative-integer?
A lens for a subsequence starting at start with length
len elements. The range behavior corresponds to
subsequence*.