-
Notifications
You must be signed in to change notification settings - Fork 13
/
example.js
19 lines (12 loc) · 857 Bytes
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
var Lenses = require('./src/lenses').expose(global)
, assert = require("assert")
, compose = require('./src/lib/pointfree').compose
;
// for demo purposes
var toUpperCase = function(x) { return x.toUpperCase(); };
var user = {name: "Bob", addresses: [{street: '99 Maple', zip: 94004, type: 'home'}, {street: '2302 Powell', zip: 94001, type: 'work'}]}
var L = makeLenses(['name', 'addresses', 'street']);
var secondAddressesStreet = compose(L.addresses, L._num(2), L.street)
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'}]}