lens icon indicating copy to clipboard operation
lens copied to clipboard

add add-lens, subtract-lens, and modulo-lens

Open AlexKnauth opened this issue 8 years ago • 3 comments

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 https://github.com/jackfirth/lens/issues/288

AlexKnauth avatar Sep 17 '16 05:09 AlexKnauth

Coverage Status

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

coveralls avatar Sep 17 '16 05:09 coveralls

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.

jackfirth avatar Sep 17 '16 15:09 jackfirth

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))

AlexKnauth avatar Sep 21 '16 21:09 AlexKnauth