by DrBoolean

DrBoolean / lenses

Composable kmett style lenses

207 Stars 13 Forks Last release: Not found 39 Commits 0 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:


Functional lenses that compose and stuff

var compose = require('pointfree-fantasy').compose;

// setup an easy test fn var toUpperCase = function(x) { return x.toUpperCase(); };

// here's the data structure var user = {name: "Bob", addresses: [{street: '99 Maple', zip: 94004, type: 'home'}, {street: '2302 Powell', zip: 94001, type: 'work'}]}

// make some lenses var L = makeLenses(['name', 'addresses', 'street']);

// compose the lenses var secondAddressesStreet = compose(L.addresses, L._num(2), L.street)

// mess with the user over(secondAddressesStreet, toUpperCase, user) // { name: 'Bob', addresses: [ { street: '99 Maple', zip: 94004, type: 'home' }, { street: '2302 POWELL', zip: 94001, type: 'work' } ] }

view(L.name, user) // 'Bob'

set(L.name, 'Kelly', user) // {name: "Kelly", addresses: [{street: '99 Maple', zip: 94004, type: 'home'}, {street: '2302 Powell', zip: 94001, type: 'work'}]}

For those not already familiar with lenses, a brief introduction can be found here


  • add traverses and folds
  • more combinators
  • prisms
  • this list is getting long...

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.