lens icon indicating copy to clipboard operation
lens copied to clipboard

add isomorphism-cond and isomorphism-join

Open AlexKnauth opened this issue 7 years ago • 1 comments

This pull request adds isomorphism-cond, isomorphism-join, lazy-isomorphism, and rec-isomorphism.

TODO: Add docs.

Examples:

(define (map-iso item-iso)
  (rec-isomorphism the-map-iso
    (isomorphism-cond
      [empty?  identity-lens  empty?]
      [cons?
       (isomorphism-join
         cons
         cons
         [first  item-iso     first]
         [rest   the-map-iso  rest])
       cons?])))

(define (tree-map-iso a? item-iso b?)
  (rec-isomorphism the-tree-iso
    (isomorphism-cond
      [a? item-iso b?]
      [list? (map-iso the-tree-iso) list?])))
 
;; Converts between a base 4 number represented as a list of digits
;; (least significant first, most significant last) and a number.
(define base4->number-iso
  (lazy-isomorphism
   (isomorphism-cond
     [empty?  (const-isomorphism '() 0)  zero?]
     [cons?
      (isomorphism-join
        cons
        (λ (r q) (+ (* 4 q) r))
        [first  identity-isomorphism  (curryr remainder 4)]
        [rest   base4->number-iso     (curryr quotient 4)])
      positive?])))

AlexKnauth avatar Nov 25 '17 19:11 AlexKnauth

Codecov Report

Merging #300 into master will increase coverage by 0.07%. The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #300      +/-   ##
==========================================
+ Coverage   97.98%   98.06%   +0.07%     
==========================================
  Files         100      101       +1     
  Lines        1736     1806      +70     
==========================================
+ Hits         1701     1771      +70     
  Misses         35       35
Impacted Files Coverage Δ
lens-common/lens/private/isomorphism/compound.rkt 100% <100%> (ø) :arrow_up:
lens-common/lens/private/isomorphism/lazy.rkt 100% <100%> (ø)
lens-data/lens/private/vector/ref.rkt 100% <0%> (ø) :arrow_up:
lens-data/lens/private/string/string.rkt 100% <0%> (ø) :arrow_up:
lens-data/lens/private/syntax/syntax.rkt 100% <0%> (ø) :arrow_up:
lens-common/lens/private/compound/if.rkt 90.9% <0%> (+0.16%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 1caa237...8f404ff. Read the comment docs.

codecov[bot] avatar Nov 25 '17 19:11 codecov[bot]