diff --git a/lens/private/compound/compose.rkt b/lens/private/compound/compose.rkt index 71b0efa..934a1fc 100644 --- a/lens/private/compound/compose.rkt +++ b/lens/private/compound/compose.rkt @@ -7,7 +7,6 @@ require racket/contract "../base/main.rkt" "../util/rest-contract.rkt" "identity.rkt" - unstable/lens/isomorphism/base module+ test require rackunit @@ -29,15 +28,7 @@ provide (define (lens-compose . args) - (match args - [(list) - identity-lens] - [(list (make-isomorphism-lens fs invs) ...) - (make-isomorphism-lens - (apply compose1 fs) - (apply compose1 (reverse invs)))] - [_ - (foldr lens-compose2 identity-lens args)])) + (foldr lens-compose2 identity-lens args)) module+ test @@ -52,5 +43,3 @@ module+ test (check-equal? (lens-view first-of-second-lens test-alist) 'b) (check-equal? (lens-set first-of-second-lens test-alist 'B) '((a 1) (B 2) (c 3))) (check-eq? (lens-compose) identity-lens) - (check-pred isomorphism-lens? (lens-compose (make-isomorphism-lens set->list list->set) - (make-isomorphism-lens list->vector vector->list))) diff --git a/unstable/lens/isomorphism.rkt b/unstable/lens/isomorphism.rkt index 7fe763a..6edc5bd 100644 --- a/unstable/lens/isomorphism.rkt +++ b/unstable/lens/isomorphism.rkt @@ -1,3 +1,4 @@ #lang reprovide "isomorphism/base.rkt" +"isomorphism/compound.rkt" "isomorphism/data.rkt" diff --git a/unstable/lens/isomorphism.scrbl b/unstable/lens/isomorphism.scrbl index bcf0f7f..244da9c 100644 --- a/unstable/lens/isomorphism.scrbl +++ b/unstable/lens/isomorphism.scrbl @@ -46,6 +46,16 @@ example, are defined like this: (make-isomorphism-lenses string->symbol symbol->string)) ]} +@defproc[(isomorphism-compose [lens isomorphism-lens?] ...) isomorphism-lens?]{ +Like @racket[lens-compose], but works only on isomorphism lenses, and returns an +isomorphism lens. +} + +@defproc[(isomorphism-thrush [lens isomorphism-lens?] ...) isomorphism-lens?]{ +Like @racket[lens-thrush], but works only on isomorphism lenses, and returns an +isomorphism lens. +} + @deflenses[[string->symbol-lens symbol->string-lens number->string-lens string->number-lens list->vector-lens vector->list-lens diff --git a/unstable/lens/isomorphism/compound.rkt b/unstable/lens/isomorphism/compound.rkt new file mode 100644 index 0000000..26b7d4f --- /dev/null +++ b/unstable/lens/isomorphism/compound.rkt @@ -0,0 +1,18 @@ +#lang sweet-exp racket/base + +provide isomorphism-compose + isomorphism-thrush + +require racket/match + "base.rkt" + +(define (isomorphism-compose . args) + (match args + [(list (make-isomorphism-lens fs invs) ...) + (make-isomorphism-lens + (apply compose1 fs) + (apply compose1 (reverse invs)))])) + +(define (isomorphism-thrush . args) + (apply isomorphism-compose (reverse args))) +