UNPKG

agson

Version:

Querying and manipulating JSON graphs

69 lines (61 loc) 1.4 kB
(function() { var Just, Nothing, identity, lens, recurse, where, _ref; _ref = require('data.maybe'), Just = _ref.Just, Nothing = _ref.Nothing; lens = require('./Lens').of; identity = require('./lenses').identity; where = function(predm) { return lens("where(" + (predm.toString()) + ")", function(ma) { return { modify: function(f) { if (!predm(ma)) { return ma; } else { return f(ma); } }, get: function() { if (!predm(ma)) { return Nothing(); } else { return ma; } } }; }); }; recurse = function(lensf) { return lens("recurse(...)", function(ma) { var end, next, store; end = { modify: function(f) { return f(ma); }, get: function() { return ma; } }; if (!ma.isJust) { return end; } else { store = lensf().runM(ma); next = store.get(); if (!next.isJust) { return end; } else { return { modify: function(f) { return store.modify(f); }, get: function() { return next; } }; } } }); }; module.exports = { where: where, recurse: recurse }; }).call(this);