UNPKG

agson

Version:

Querying and manipulating JSON graphs

70 lines (53 loc) 2.03 kB
(function() { var Lens, Maybe, Store, Traversal, maybeMap, __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'); maybeMap = require('./util').maybeMap; Store = require('./Store'); Lens = require('./Lens'); module.exports = Traversal = (function(_super) { __extends(Traversal, _super); function Traversal() { this.then = __bind(this.then, this); return Traversal.__super__.constructor.apply(this, arguments); } Traversal.of = function(description, fs) { return new ((function(_super1) { __extends(_Class, _super1); function _Class() { return _Class.__super__.constructor.apply(this, arguments); } _Class.prototype.runM = function(mt) { return Store.of(Maybe)(fs(mt)); }; _Class.prototype.toString = function() { return description; }; return _Class; })(Traversal)); }; Traversal.prototype.then = function(bc) { return Traversal.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 _this.runM(ma).get().map(function(bs) { return maybeMap(bs, function(b) { return bc.run(b).get(); }); }); } }; }; })(this)); }; return Traversal; })(Lens); }).call(this);