Package Exports
- lenses
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (lenses) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
lenses.js
Functional lenses that compose and stuff
require('./src/lenses').expose(global);
var compose = require('./src/lib/pointfree').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, _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'}]}