add list-ref-nested-lens

This commit is contained in:
AlexKnauth 2015-07-05 09:34:00 -04:00
parent 70fb6fa1b2
commit f65e1936bb

View File

@ -1,6 +1,7 @@
#lang racket/base
(provide list-ref-lens
list-ref-nested-lens
take-lens
drop-lens
first-lens
@ -35,6 +36,9 @@
(define (list-ref-lens i)
(lens-compose car-lens (drop-lens i)))
(define (list-ref-nested-lens . args)
(apply lens-thrush (map list-ref-lens args)))
(define first-lens (list-ref-lens 0))
(define second-lens (list-ref-lens 1))
(define third-lens (list-ref-lens 2))
@ -57,6 +61,8 @@
(check-equal? (lens-set third-lens '(1 2 3 4 5) 'a) '(1 2 a 4 5))
(check-equal? (lens-set fourth-lens '(1 2 3 4 5) 'a) '(1 2 3 a 5))
(check-equal? (lens-set fifth-lens '(1 2 3 4 5) 'a) '(1 2 3 4 a))
(check-equal? (lens-transform* '(a (b c) (d e f)) (list-ref-nested-lens 2 1) symbol->string)
'(a (b c) (d "e" f)))
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;