A Racket package for creating and composing pure functional lenses
Go to file
2015-08-28 10:16:16 -07:00
lens split functional-dict? predicate into separate module 2015-08-27 21:13:00 -04:00
unstable provide and document dict-ref-nested-lens 2015-08-27 21:27:30 -04:00
.gitignore Add documentation coverage test, remove undocumented exports 2015-07-06 12:52:04 -07:00
.travis.yml put raco cover in after_success 2015-08-19 13:25:04 -04:00
info.rkt Use scribble-example 2015-08-27 14:46:13 -07:00
README.md Update README.md 2015-08-28 10:16:16 -07:00

lens Build Status Coverage Status Stories in Ready Scribble Docs Scribble Docs (unstable) Version

A Racket package for creating and composing pure functional lenses.

raco pkg install lens (require lens)

A lens is a value that can be used to focus on a small subpiece of some larger structure. Given a lens and a value of that larger structure, two values can be dervied: a view value, which is the subpiece, and a context function, which accepts a new view value and returns a new structure with the old view replaced by the new view. Think of them as composable, pure functional getters and setters. See the full documentation for more detail.

> (lens-view first-lens '(1 2 3))
1
> (lens-set first-lens '(1 2 3) 'a)
'(a 2 3)
> (lens-transform first-lens '(1 2 3) number->string)
'("1" 2 3)
> (define first-of-b-key-lens (lens-compose first-lens (hash-ref-lens 'b)))
> (define a-hash (hash 'a '(1 2 3) 'b '(10 20 30) 'c '(100 200 300)))
> (lens-view first-of-b-key-lens a-hash)
10
> (lens-set first-of-b-key-lens a-hash 'foo)
#hash((a . (1 2 3)) (b . (foo 20 30)) (c . (100 200 300)))

Contributions

This project uses Github issues organized by a Waffle board to track what's being worked on. Check the board to see if there's any features, bugs, etc. that interest you, or create a new Github issue to inquire about something you'd like to see changed.