agson
Version:
Querying and manipulating JSON graphs
42 lines (39 loc) • 1.04 kB
JavaScript
(function() {
var __hasProp = {}.hasOwnProperty;
module.exports = {
notImplemented: function() {
throw new Error('not implemented');
},
maybeMap: function(xs, f) {
var maybeY, x, ys, _i, _len;
ys = [];
for (_i = 0, _len = xs.length; _i < _len; _i++) {
x = xs[_i];
maybeY = f(x);
if (maybeY.isJust) {
ys.push(maybeY.get());
}
}
return ys;
},
maybeMapValues: function(object, f) {
var key, maybeV, result, value;
result = {};
for (key in object) {
if (!__hasProp.call(object, key)) continue;
value = object[key];
maybeV = f(value);
if (maybeV.isJust) {
result[key] = maybeV.get();
}
}
return result;
},
isArray: function(input) {
return (Object.prototype.toString.call(input)) === '[object Array]';
},
isObject: function(input) {
return (Object.prototype.toString.call(input)) === '[object Object]';
}
};
}).call(this);