Skip to content

add add-lens, subtract-lens, and modulo-lens#289

Open
AlexKnauth wants to merge 1 commit into
jackfirth:masterfrom
AlexKnauth:data-number
Open

add add-lens, subtract-lens, and modulo-lens#289
AlexKnauth wants to merge 1 commit into
jackfirth:masterfrom
AlexKnauth:data-number

Conversation

@AlexKnauth

Copy link
Copy Markdown
Collaborator

I still need to provide it from unstable/lens and add it to the unstable docs.

> (lens-view (add-lens 5) 3)
8
> (lens-set (add-lens 5) 3 8)
3
> (lens-set (add-lens 5) 3 27)
22
> (lens-view (modulo-lens 10) 2)
2
> (lens-set (modulo-lens 10) 2 8)
8
> (lens-view (modulo-lens 10) 23)
3
> (lens-set (modulo-lens 10) 23 9)
29

Resolves #288

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.01%) to 98.937% when pulling de41ec0 on AlexKnauth:data-number into 11ecc2f on jackfirth:master.

@jackfirth

Copy link
Copy Markdown
Owner

add-lens and subtract-lens don't seem as useful, since they're just isomorphisms that don't do any destructuring.

This has me thinking about #205 again. Since that issue was last discussed, I've run into cases where I want just isomorphisms and don't care about lenses. As we add more utility isomorphisms like add and subtract, there will be more use in having isomorphisms separate.

@AlexKnauth

AlexKnauth commented Sep 21, 2016

Copy link
Copy Markdown
Collaborator Author

I just ran into a situation where a multiply-lens (for non-zero scalar inputs) would be useful. I wanted a round-to-the-nearest-thousandth function and I wanted

(define round-to-the-nearest-thousandth (lens-transform (multiply-lens 1000) _ exact-round))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Modulo lens

3 participants