UNPKG

graphdb

Version:

Javascript client library supporting GraphDB and RDF4J REST API.

78 lines (74 loc) 3.28 kB
"use strict"; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); } function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } } function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /** * Utility class allowing to iterate a collection. * * Note: This should be used with immutable collections, e.g no add or remove * operations should be performed while iterating. * * @class * @author Mihail Radkov * @author Svilen Velikov */ var Iterable = /*#__PURE__*/function () { /** * Constructs new iterable for the provided collection. * * @param {Object[]} iterable the collection to iterate */ function Iterable(iterable) { _classCallCheck(this, Iterable); this.iterable = iterable; this.index = 0; this.size = iterable.length; } /** * Returns if there are elements left to be iterated from the collection. * * Use this method before calling {@link next()} to avoid out of bounds error. * * @return {boolean} <code>true</code> if there is at least single element * left to iterate or <code>false</code> otherwise */ return _createClass(Iterable, [{ key: "hasNext", value: function hasNext() { return this.index < this.size; } /** * Returns the next object from the iterable collection. * * Before invoking this method, check if there are elements to iterate by * using {@link hasNext()} because if there are no objects left to iterate, * the function will blow with an error. * * @return {Object} the next iterated object from the collection * @throws {Error} if there are no more elements to be iterated */ }, { key: "next", value: function next() { if (!this.hasNext()) { throw new Error('There are no elements left to iterate!'); } return this.iterable[this.index++]; } /** * Resets the iterable to begin from the start as if it was just constructed. * * @return {Iterable} the current iterable for method chaining. */ }, { key: "reset", value: function reset() { this.index = 0; return this; } }]); }(); module.exports = Iterable;