UNPKG

agson

Version:

Querying and manipulating JSON graphs

67 lines (50 loc) 1.86 kB
(function() { var Lens, Maybe, Store, notImplemented, __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; Maybe = require('data.maybe'); notImplemented = require('./util').notImplemented; Store = require('./Store'); module.exports = Lens = (function() { function Lens() { this.then = __bind(this.then, this); } Lens.of = function(description, fs) { return new ((function(_super) { __extends(_Class, _super); function _Class() { return _Class.__super__.constructor.apply(this, arguments); } _Class.prototype.runM = function(ma) { return Store.of(Maybe)(fs(ma)); }; _Class.prototype.toString = function() { return description; }; return _Class; })(Lens)); }; Lens.prototype.runM = notImplemented; Lens.prototype.run = function(a) { return this.runM(Maybe.fromNullable(a)); }; Lens.prototype.then = function(bc) { return Lens.of("" + (this.toString()) + ".then(" + (bc.toString()) + ")", (function(_this) { return function(ma) { return { modify: function(f) { return _this.runM(ma).modify(function(mb) { return bc.runM(mb).modify(f); }); }, get: function() { return bc.runM(_this.runM(ma).get()).get(); } }; }; })(this)); }; return Lens; })(); }).call(this);