9.0.0.3
Lenses for Generic Collections
| (require alexis/collection/lens) | |
| package: alexis-collection-lens | |
This provides lenses that examine and modify generic collections.
procedure
key : any/c (ref-lens key default) → lens? key : any/c default : any/c
Constructs a lens for a keyed value of an indexable? instance.
Examples:
> (lens-transform (ref-lens 'key) (hash 'key 2) (λ (x) (* 10 x))) '#hash((key . 20))
> (lens-view (ref-lens 'key 'default) (hash)) 'default
Constructs a lens for a single element of a sequence?.
Example:
> (lens-transform (nth-lens 1) '(1 2 3) (λ (x) (* 10 x))) '(1 20 3)
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)))
A lens for the first element of a sequence?.
A lens for all but the first element of a sequence?.
Constructs a lens for the first n elements of a
sequence?.
Constructs a lens for the rest of a sequence? after the first
n elements.
procedure
start : exact-nonnegative-integer? end : exact-nonnegative-integer?
A lens for a subsequence from start to end. The range
behavior corresponds to subsequence.
procedure
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*.