Fantasy Lenses
Lenses are composable, immutable getters and setters. Composable in that they allow updating of nested data structures. Immutable in that the setters return copies of the whole data structure.
Examples
Nested updating
var person = name: "Brian McKenna" location: number: 1006 street: "Pearl St" postcode: 80302 objectLens = LensobjectLens locationLens = numberLens = store = locationLens; console;// 1006 console;// { name: 'Brian McKenna',// location: { number: 1007, street: 'Pearl St', postcode: 80302 } }
Accessing optional fields
var data = name: "First record" config: type: 2 description: "Hello world" config: type: 3 name: "Third record" objectLens = PartialLensobjectLens configLens = typeLens = configTypeLens = configLens; console;// [ { name: 'First record', config: { type: 2 } } ]