Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@lumino/algorithm

Package Overview
Dependencies
Maintainers
6
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lumino/algorithm - npm Package Compare versions

Comparing version 1.9.2 to 2.0.0-alpha.0

2

dist/index.min.js

@@ -1,2 +0,2 @@

!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((t="undefined"!=typeof globalThis?globalThis:t||self).lumino_algorithm={})}(this,(function(t){"use strict";function n(t){return"function"==typeof t.iter?t.iter():new e(t)}function r(t,r){for(var e,i=0,o=n(t);void 0!==(e=o.next());)if(!1===r(e,i++))return}t.ArrayExt=void 0,function(t){function n(t,n,r,e){void 0===r&&(r=0),void 0===e&&(e=-1);var i,o=t.length;if(0===o)return-1;r=r<0?Math.max(0,r+o):Math.min(r,o-1),i=(e=e<0?Math.max(0,e+o):Math.min(e,o-1))<r?e+1+(o-r):e-r+1;for(var u=0;u<i;++u){var a=(r+u)%o;if(t[a]===n)return a}return-1}function r(t,n,r,e){void 0===r&&(r=-1),void 0===e&&(e=0);var i,o=t.length;if(0===o)return-1;i=(r=r<0?Math.max(0,r+o):Math.min(r,o-1))<(e=e<0?Math.max(0,e+o):Math.min(e,o-1))?r+1+(o-e):r-e+1;for(var u=0;u<i;++u){var a=(r-u+o)%o;if(t[a]===n)return a}return-1}function e(t,n,r,e){void 0===r&&(r=0),void 0===e&&(e=-1);var i,o=t.length;if(0===o)return-1;r=r<0?Math.max(0,r+o):Math.min(r,o-1),i=(e=e<0?Math.max(0,e+o):Math.min(e,o-1))<r?e+1+(o-r):e-r+1;for(var u=0;u<i;++u){var a=(r+u)%o;if(n(t[a],a))return a}return-1}function i(t,n,r,e){void 0===r&&(r=-1),void 0===e&&(e=0);var i,o=t.length;if(0===o)return-1;i=(r=r<0?Math.max(0,r+o):Math.min(r,o-1))<(e=e<0?Math.max(0,e+o):Math.min(e,o-1))?r+1+(o-e):r-e+1;for(var u=0;u<i;++u){var a=(r-u+o)%o;if(n(t[a],a))return a}return-1}function o(t,n,r){void 0===n&&(n=0),void 0===r&&(r=-1);var e=t.length;if(!(e<=1))for(n=n<0?Math.max(0,n+e):Math.min(n,e-1),r=r<0?Math.max(0,r+e):Math.min(r,e-1);n<r;){var i=t[n],o=t[r];t[n++]=o,t[r--]=i}}function u(t,n){var r=t.length;if(n<0&&(n+=r),!(n<0||n>=r)){for(var e=t[n],i=n+1;i<r;++i)t[i-1]=t[i];return t.length=r-1,e}}t.firstIndexOf=n,t.lastIndexOf=r,t.findFirstIndex=e,t.findLastIndex=i,t.findFirstValue=function(t,n,r,i){void 0===r&&(r=0),void 0===i&&(i=-1);var o=e(t,n,r,i);return-1!==o?t[o]:void 0},t.findLastValue=function(t,n,r,e){void 0===r&&(r=-1),void 0===e&&(e=0);var o=i(t,n,r,e);return-1!==o?t[o]:void 0},t.lowerBound=function(t,n,r,e,i){void 0===e&&(e=0),void 0===i&&(i=-1);var o=t.length;if(0===o)return 0;for(var u=e=e<0?Math.max(0,e+o):Math.min(e,o-1),a=(i=i<0?Math.max(0,i+o):Math.min(i,o-1))-e+1;a>0;){var f=a>>1,h=u+f;r(t[h],n)<0?(u=h+1,a-=f+1):a=f}return u},t.upperBound=function(t,n,r,e,i){void 0===e&&(e=0),void 0===i&&(i=-1);var o=t.length;if(0===o)return 0;for(var u=e=e<0?Math.max(0,e+o):Math.min(e,o-1),a=(i=i<0?Math.max(0,i+o):Math.min(i,o-1))-e+1;a>0;){var f=a>>1,h=u+f;r(t[h],n)>0?a=f:(u=h+1,a-=f+1)}return u},t.shallowEqual=function(t,n,r){if(t===n)return!0;if(t.length!==n.length)return!1;for(var e=0,i=t.length;e<i;++e)if(r?!r(t[e],n[e]):t[e]!==n[e])return!1;return!0},t.slice=function(t,n){void 0===n&&(n={});var r=n.start,e=n.stop,i=n.step;if(void 0===i&&(i=1),0===i)throw new Error("Slice `step` cannot be zero.");var o,u=t.length;void 0===r?r=i<0?u-1:0:r<0?r=Math.max(r+u,i<0?-1:0):r>=u&&(r=i<0?u-1:u),void 0===e?e=i<0?-1:u:e<0?e=Math.max(e+u,i<0?-1:0):e>=u&&(e=i<0?u-1:u),o=i<0&&e>=r||i>0&&r>=e?0:i<0?Math.floor((e-r+1)/i+1):Math.floor((e-r-1)/i+1);for(var a=[],f=0;f<o;++f)a[f]=t[r+f*i];return a},t.move=function(t,n,r){var e=t.length;if(!(e<=1)&&(n=n<0?Math.max(0,n+e):Math.min(n,e-1))!==(r=r<0?Math.max(0,r+e):Math.min(r,e-1))){for(var i=t[n],o=n<r?1:-1,u=n;u!==r;u+=o)t[u]=t[u+o];t[r]=i}},t.reverse=o,t.rotate=function(t,n,r,e){void 0===r&&(r=0),void 0===e&&(e=-1);var i=t.length;if(!(i<=1||(r=r<0?Math.max(0,r+i):Math.min(r,i-1))>=(e=e<0?Math.max(0,e+i):Math.min(e,i-1)))){var u=e-r+1;if(n>0?n%=u:n<0&&(n=(n%u+u)%u),0!==n){var a=r+n;o(t,r,a-1),o(t,a,e),o(t,r,e)}}},t.fill=function(t,n,r,e){void 0===r&&(r=0),void 0===e&&(e=-1);var i=t.length;if(0!==i){var o;r=r<0?Math.max(0,r+i):Math.min(r,i-1),o=(e=e<0?Math.max(0,e+i):Math.min(e,i-1))<r?e+1+(i-r):e-r+1;for(var u=0;u<o;++u)t[(r+u)%i]=n}},t.insert=function(t,n,r){var e=t.length;n=n<0?Math.max(0,n+e):Math.min(n,e);for(var i=e;i>n;--i)t[i]=t[i-1];t[n]=r},t.removeAt=u,t.removeFirstOf=function(t,r,e,i){void 0===e&&(e=0),void 0===i&&(i=-1);var o=n(t,r,e,i);return-1!==o&&u(t,o),o},t.removeLastOf=function(t,n,e,i){void 0===e&&(e=-1),void 0===i&&(i=0);var o=r(t,n,e,i);return-1!==o&&u(t,o),o},t.removeAllOf=function(t,n,r,e){void 0===r&&(r=0),void 0===e&&(e=-1);var i=t.length;if(0===i)return 0;r=r<0?Math.max(0,r+i):Math.min(r,i-1),e=e<0?Math.max(0,e+i):Math.min(e,i-1);for(var o=0,u=0;u<i;++u)r<=e&&u>=r&&u<=e&&t[u]===n||e<r&&(u<=e||u>=r)&&t[u]===n?o++:o>0&&(t[u-o]=t[u]);return o>0&&(t.length=i-o),o},t.removeFirstWhere=function(t,n,r,i){var o;void 0===r&&(r=0),void 0===i&&(i=-1);var a=e(t,n,r,i);return-1!==a&&(o=u(t,a)),{index:a,value:o}},t.removeLastWhere=function(t,n,r,e){var o;void 0===r&&(r=-1),void 0===e&&(e=0);var a=i(t,n,r,e);return-1!==a&&(o=u(t,a)),{index:a,value:o}},t.removeAllWhere=function(t,n,r,e){void 0===r&&(r=0),void 0===e&&(e=-1);var i=t.length;if(0===i)return 0;r=r<0?Math.max(0,r+i):Math.min(r,i-1),e=e<0?Math.max(0,e+i):Math.min(e,i-1);for(var o=0,u=0;u<i;++u)r<=e&&u>=r&&u<=e&&n(t[u],u)||e<r&&(u<=e||u>=r)&&n(t[u],u)?o++:o>0&&(t[u-o]=t[u]);return o>0&&(t.length=i-o),o}}(t.ArrayExt||(t.ArrayExt={}));var e=function(){function t(t){this._index=0,this._source=t}return t.prototype.iter=function(){return this},t.prototype.clone=function(){var n=new t(this._source);return n._index=this._index,n},t.prototype.next=function(){if(!(this._index>=this._source.length))return this._source[this._index++]},t}(),i=function(){function t(t,n){void 0===n&&(n=Object.keys(t)),this._index=0,this._source=t,this._keys=n}return t.prototype.iter=function(){return this},t.prototype.clone=function(){var n=new t(this._source,this._keys);return n._index=this._index,n},t.prototype.next=function(){if(!(this._index>=this._keys.length)){var t=this._keys[this._index++];return t in this._source?t:this.next()}},t}(),o=function(){function t(t,n){void 0===n&&(n=Object.keys(t)),this._index=0,this._source=t,this._keys=n}return t.prototype.iter=function(){return this},t.prototype.clone=function(){var n=new t(this._source,this._keys);return n._index=this._index,n},t.prototype.next=function(){if(!(this._index>=this._keys.length)){var t=this._keys[this._index++];return t in this._source?this._source[t]:this.next()}},t}(),u=function(){function t(t,n){void 0===n&&(n=Object.keys(t)),this._index=0,this._source=t,this._keys=n}return t.prototype.iter=function(){return this},t.prototype.clone=function(){var n=new t(this._source,this._keys);return n._index=this._index,n},t.prototype.next=function(){if(!(this._index>=this._keys.length)){var t=this._keys[this._index++];return t in this._source?[t,this._source[t]]:this.next()}},t}(),a=function(){function t(t){this._fn=t}return t.prototype.iter=function(){return this},t.prototype.clone=function(){throw new Error("An `FnIterator` cannot be cloned.")},t.prototype.next=function(){return this._fn.call(void 0)},t}();var f=function(){function t(t){this._cloned=!1,this._source=t,this._active=void 0}return t.prototype.iter=function(){return this},t.prototype.clone=function(){var n=new t(this._source.clone());return n._active=this._active&&this._active.clone(),n._cloned=!0,this._cloned=!0,n},t.prototype.next=function(){if(void 0===this._active){var t=this._source.next();if(void 0===t)return;this._active=this._cloned?t.clone():t}var n=this._active.next();return void 0!==n?n:(this._active=void 0,this.next())},t}();var h=function(){function t(){}return t.prototype.iter=function(){return this},t.prototype.clone=function(){return new t},t.prototype.next=function(){},t}();var c=function(){function t(t,n){this._source=t,this._index=n}return t.prototype.iter=function(){return this},t.prototype.clone=function(){return new t(this._source.clone(),this._index)},t.prototype.next=function(){var t=this._source.next();if(void 0!==t)return[this._index++,t]},t}();var s=function(){function t(t,n){this._index=0,this._source=t,this._fn=n}return t.prototype.iter=function(){return this},t.prototype.clone=function(){var n=new t(this._source.clone(),this._fn);return n._index=this._index,n},t.prototype.next=function(){for(var t,n=this._fn,r=this._source;void 0!==(t=r.next());)if(n(t,this._index++))return t},t}();var v=function(){function t(t,n){this._index=0,this._source=t,this._fn=n}return t.prototype.iter=function(){return this},t.prototype.clone=function(){var n=new t(this._source.clone(),this._fn);return n._index=this._index,n},t.prototype.next=function(){var t=this._source.next();if(void 0!==t)return this._fn.call(void 0,t,this._index++)},t}();var d,_=function(){function t(t,n,r){this._index=0,this._start=t,this._stop=n,this._step=r,this._length=d.rangeLength(t,n,r)}return t.prototype.iter=function(){return this},t.prototype.clone=function(){var n=new t(this._start,this._stop,this._step);return n._index=this._index,n},t.prototype.next=function(){if(!(this._index>=this._length))return this._start+this._step*this._index++},t}();!function(t){t.rangeLength=function(t,n,r){return 0===r?1/0:t>n&&r>0||t<n&&r<0?0:Math.ceil((n-t)/r)}}(d||(d={}));var p=function(){function t(t,n){this._value=t,this._count=n}return t.prototype.iter=function(){return this},t.prototype.clone=function(){return new t(this._value,this._count)},t.prototype.next=function(){if(!(this._count<=0))return this._count--,this._value},t}();var x=function(){function t(t){this._source=t,this._index=t.length-1}return t.prototype.iter=function(){return this},t.prototype.clone=function(){var n=new t(this._source);return n._index=this._index,n},t.prototype.next=function(){if(!(this._index<0||this._index>=this._source.length))return this._source[this._index--]},t}();var l=function(){function t(t,n){this._source=t,this._step=n}return t.prototype.iter=function(){return this},t.prototype.clone=function(){return new t(this._source.clone(),this._step)},t.prototype.next=function(){for(var t=this._source.next(),n=this._step-1;n>0;--n)this._source.next();return t},t}();t.StringExt=void 0,function(t){function n(t,n,r){void 0===r&&(r=0);for(var e=new Array(n.length),i=0,o=r,u=n.length;i<u;++i,++o){if(-1===(o=t.indexOf(n[i],o)))return null;e[i]=o}return e}t.findIndices=n,t.matchSumOfSquares=function(t,r,e){void 0===e&&(e=0);var i=n(t,r,e);if(!i)return null;for(var o=0,u=0,a=i.length;u<a;++u){var f=i[u]-e;o+=f*f}return{score:o,indices:i}},t.matchSumOfDeltas=function(t,r,e){void 0===e&&(e=0);var i=n(t,r,e);if(!i)return null;for(var o=0,u=e-1,a=0,f=i.length;a<f;++a){var h=i[a];o+=h-u-1,u=h}return{score:o,indices:i}},t.highlight=function(t,n,r){for(var e=[],i=0,o=0,u=n.length;i<u;){for(var a=n[i],f=n[i];++i<u&&n[i]===f+1;)f++;o<a&&e.push(t.slice(o,a)),a<f+1&&e.push(r(t.slice(a,f+1))),o=f+1}return o<t.length&&e.push(t.slice(o)),e},t.cmp=function(t,n){return t<n?-1:t>n?1:0}}(t.StringExt||(t.StringExt={}));var m=function(){function t(t,n){this._source=t,this._count=n}return t.prototype.iter=function(){return this},t.prototype.clone=function(){return new t(this._source.clone(),this._count)},t.prototype.next=function(){if(!(this._count<=0)){var t=this._source.next();if(void 0!==t)return this._count--,t}},t}();var y=function(){function t(t){this._source=t}return t.prototype.iter=function(){return this},t.prototype.clone=function(){return new t(this._source.map((function(t){return t.clone()})))},t.prototype.next=function(){for(var t=new Array(this._source.length),n=0,r=this._source.length;n<r;++n){var e=this._source[n].next();if(void 0===e)return;t[n]=e}return t},t}();t.ArrayIterator=e,t.ChainIterator=f,t.EmptyIterator=h,t.EnumerateIterator=c,t.FilterIterator=s,t.FnIterator=a,t.ItemIterator=u,t.KeyIterator=i,t.MapIterator=v,t.RangeIterator=_,t.RepeatIterator=p,t.RetroArrayIterator=x,t.StrideIterator=l,t.TakeIterator=m,t.ValueIterator=o,t.ZipIterator=y,t.chain=function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return new f(n(t.map(n)))},t.each=r,t.empty=function(){return new h},t.enumerate=function(t,r){return void 0===r&&(r=0),new c(n(t),r)},t.every=function(t,r){for(var e,i=0,o=n(t);void 0!==(e=o.next());)if(!r(e,i++))return!1;return!0},t.filter=function(t,r){return new s(n(t),r)},t.find=function(t,r){for(var e,i=0,o=n(t);void 0!==(e=o.next());)if(r(e,i++))return e},t.findIndex=function(t,r){for(var e,i=0,o=n(t);void 0!==(e=o.next());)if(r(e,i++))return i-1;return-1},t.iter=n,t.iterFn=function(t){return new a(t)},t.iterItems=function(t){return new u(t)},t.iterKeys=function(t){return new i(t)},t.iterValues=function(t){return new o(t)},t.map=function(t,r){return new v(n(t),r)},t.max=function(t,r){var e=n(t),i=e.next();if(void 0!==i){for(var o=i;void 0!==(i=e.next());)r(i,o)>0&&(o=i);return o}},t.min=function(t,r){var e=n(t),i=e.next();if(void 0!==i){for(var o=i;void 0!==(i=e.next());)r(i,o)<0&&(o=i);return o}},t.minmax=function(t,r){var e=n(t),i=e.next();if(void 0!==i){for(var o=i,u=i;void 0!==(i=e.next());)r(i,o)<0?o=i:r(i,u)>0&&(u=i);return[o,u]}},t.once=function(t){return new p(t,1)},t.range=function(t,n,r){return void 0===n?new _(0,t,1):new _(t,n,void 0===r?1:r)},t.reduce=function(t,r,e){var i=0,o=n(t),u=o.next();if(void 0===u&&void 0===e)throw new TypeError("Reduce of empty iterable with no initial value.");if(void 0===u)return e;var a,f,h=o.next();if(void 0===h&&void 0===e)return u;if(void 0===h)return r(e,u,i++);for(a=r(void 0===e?u:r(e,u,i++),h,i++);void 0!==(f=o.next());)a=r(a,f,i++);return a},t.repeat=function(t,n){return new p(t,n)},t.retro=function(t){return"function"==typeof t.retro?t.retro():new x(t)},t.some=function(t,r){for(var e,i=0,o=n(t);void 0!==(e=o.next());)if(r(e,i++))return!0;return!1},t.stride=function(t,r){return new l(n(t),r)},t.take=function(t,r){return new m(n(t),r)},t.toArray=function(t){for(var r,e=0,i=[],o=n(t);void 0!==(r=o.next());)i[e++]=r;return i},t.toObject=function(t){for(var r,e=n(t),i={};void 0!==(r=e.next());)i[r[0]]=r[1];return i},t.topologicSort=function(t){var n=[],e=new Set,i=new Map;return r(t,(function(t){var n=t[0],r=t[1],e=i.get(r);e?e.push(n):i.set(r,[n])})),i.forEach((function(t,n){o(n)})),n;function o(t){if(!e.has(t)){e.add(t);var r=i.get(t);r&&r.forEach(o),n.push(t)}}},t.zip=function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return new y(t.map(n))},Object.defineProperty(t,"__esModule",{value:!0})}));
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).lumino_algorithm={})}(this,(function(t){"use strict";function e(t,e){let n=0;for(const r of t)if(!1===e(r,n++))return!1;return!0}var n;t.ArrayExt=void 0,function(t){function e(t,e,n=0,r=-1){let o,i=t.length;if(0===i)return-1;n=n<0?Math.max(0,n+i):Math.min(n,i-1),o=(r=r<0?Math.max(0,r+i):Math.min(r,i-1))<n?r+1+(i-n):r-n+1;for(let r=0;r<o;++r){let o=(n+r)%i;if(t[o]===e)return o}return-1}function n(t,e,n=-1,r=0){let o,i=t.length;if(0===i)return-1;o=(n=n<0?Math.max(0,n+i):Math.min(n,i-1))<(r=r<0?Math.max(0,r+i):Math.min(r,i-1))?n+1+(i-r):n-r+1;for(let r=0;r<o;++r){let o=(n-r+i)%i;if(t[o]===e)return o}return-1}function r(t,e,n=0,r=-1){let o,i=t.length;if(0===i)return-1;n=n<0?Math.max(0,n+i):Math.min(n,i-1),o=(r=r<0?Math.max(0,r+i):Math.min(r,i-1))<n?r+1+(i-n):r-n+1;for(let r=0;r<o;++r){let o=(n+r)%i;if(e(t[o],o))return o}return-1}function o(t,e,n=-1,r=0){let o,i=t.length;if(0===i)return-1;o=(n=n<0?Math.max(0,n+i):Math.min(n,i-1))<(r=r<0?Math.max(0,r+i):Math.min(r,i-1))?n+1+(i-r):n-r+1;for(let r=0;r<o;++r){let o=(n-r+i)%i;if(e(t[o],o))return o}return-1}function i(t,e=0,n=-1){let r=t.length;if(!(r<=1))for(e=e<0?Math.max(0,e+r):Math.min(e,r-1),n=n<0?Math.max(0,n+r):Math.min(n,r-1);e<n;){let r=t[e],o=t[n];t[e++]=o,t[n--]=r}}function f(t,e){let n=t.length;if(e<0&&(e+=n),e<0||e>=n)return;let r=t[e];for(let r=e+1;r<n;++r)t[r-1]=t[r];return t.length=n-1,r}t.firstIndexOf=e,t.lastIndexOf=n,t.findFirstIndex=r,t.findLastIndex=o,t.findFirstValue=function(t,e,n=0,o=-1){let i=r(t,e,n,o);return-1!==i?t[i]:void 0},t.findLastValue=function(t,e,n=-1,r=0){let i=o(t,e,n,r);return-1!==i?t[i]:void 0},t.lowerBound=function(t,e,n,r=0,o=-1){let i=t.length;if(0===i)return 0;let f=r=r<0?Math.max(0,r+i):Math.min(r,i-1),l=(o=o<0?Math.max(0,o+i):Math.min(o,i-1))-r+1;for(;l>0;){let r=l>>1,o=f+r;n(t[o],e)<0?(f=o+1,l-=r+1):l=r}return f},t.upperBound=function(t,e,n,r=0,o=-1){let i=t.length;if(0===i)return 0;let f=r=r<0?Math.max(0,r+i):Math.min(r,i-1),l=(o=o<0?Math.max(0,o+i):Math.min(o,i-1))-r+1;for(;l>0;){let r=l>>1,o=f+r;n(t[o],e)>0?l=r:(f=o+1,l-=r+1)}return f},t.shallowEqual=function(t,e,n){if(t===e)return!0;if(t.length!==e.length)return!1;for(let r=0,o=t.length;r<o;++r)if(n?!n(t[r],e[r]):t[r]!==e[r])return!1;return!0},t.slice=function(t,e={}){let{start:n,stop:r,step:o}=e;if(void 0===o&&(o=1),0===o)throw new Error("Slice `step` cannot be zero.");let i,f=t.length;void 0===n?n=o<0?f-1:0:n<0?n=Math.max(n+f,o<0?-1:0):n>=f&&(n=o<0?f-1:f),void 0===r?r=o<0?-1:f:r<0?r=Math.max(r+f,o<0?-1:0):r>=f&&(r=o<0?f-1:f),i=o<0&&r>=n||o>0&&n>=r?0:o<0?Math.floor((r-n+1)/o+1):Math.floor((r-n-1)/o+1);let l=[];for(let e=0;e<i;++e)l[e]=t[n+e*o];return l},t.move=function(t,e,n){let r=t.length;if(r<=1)return;if((e=e<0?Math.max(0,e+r):Math.min(e,r-1))===(n=n<0?Math.max(0,n+r):Math.min(n,r-1)))return;let o=t[e],i=e<n?1:-1;for(let r=e;r!==n;r+=i)t[r]=t[r+i];t[n]=o},t.reverse=i,t.rotate=function(t,e,n=0,r=-1){let o=t.length;if(o<=1)return;if((n=n<0?Math.max(0,n+o):Math.min(n,o-1))>=(r=r<0?Math.max(0,r+o):Math.min(r,o-1)))return;let f=r-n+1;if(e>0?e%=f:e<0&&(e=(e%f+f)%f),0===e)return;let l=n+e;i(t,n,l-1),i(t,l,r),i(t,n,r)},t.fill=function(t,e,n=0,r=-1){let o,i=t.length;if(0!==i){n=n<0?Math.max(0,n+i):Math.min(n,i-1),o=(r=r<0?Math.max(0,r+i):Math.min(r,i-1))<n?r+1+(i-n):r-n+1;for(let r=0;r<o;++r)t[(n+r)%i]=e}},t.insert=function(t,e,n){let r=t.length;e=e<0?Math.max(0,e+r):Math.min(e,r);for(let n=r;n>e;--n)t[n]=t[n-1];t[e]=n},t.removeAt=f,t.removeFirstOf=function(t,n,r=0,o=-1){let i=e(t,n,r,o);return-1!==i&&f(t,i),i},t.removeLastOf=function(t,e,r=-1,o=0){let i=n(t,e,r,o);return-1!==i&&f(t,i),i},t.removeAllOf=function(t,e,n=0,r=-1){let o=t.length;if(0===o)return 0;n=n<0?Math.max(0,n+o):Math.min(n,o-1),r=r<0?Math.max(0,r+o):Math.min(r,o-1);let i=0;for(let f=0;f<o;++f)n<=r&&f>=n&&f<=r&&t[f]===e||r<n&&(f<=r||f>=n)&&t[f]===e?i++:i>0&&(t[f-i]=t[f]);return i>0&&(t.length=o-i),i},t.removeFirstWhere=function(t,e,n=0,o=-1){let i,l=r(t,e,n,o);return-1!==l&&(i=f(t,l)),{index:l,value:i}},t.removeLastWhere=function(t,e,n=-1,r=0){let i,l=o(t,e,n,r);return-1!==l&&(i=f(t,l)),{index:l,value:i}},t.removeAllWhere=function(t,e,n=0,r=-1){let o=t.length;if(0===o)return 0;n=n<0?Math.max(0,n+o):Math.min(n,o-1),r=r<0?Math.max(0,r+o):Math.min(r,o-1);let i=0;for(let f=0;f<o;++f)n<=r&&f>=n&&f<=r&&e(t[f],f)||r<n&&(f<=r||f>=n)&&e(t[f],f)?i++:i>0&&(t[f-i]=t[f]);return i>0&&(t.length=o-i),i}}(t.ArrayExt||(t.ArrayExt={})),function(t){t.rangeLength=function(t,e,n){return 0===n?1/0:t>e&&n>0||t<e&&n<0?0:Math.ceil((e-t)/n)}}(n||(n={})),t.StringExt=void 0,function(t){function e(t,e,n=0){let r=new Array(e.length);for(let o=0,i=n,f=e.length;o<f;++o,++i){if(i=t.indexOf(e[o],i),-1===i)return null;r[o]=i}return r}t.findIndices=e,t.matchSumOfSquares=function(t,n,r=0){let o=e(t,n,r);if(!o)return null;let i=0;for(let t=0,e=o.length;t<e;++t){let e=o[t]-r;i+=e*e}return{score:i,indices:o}},t.matchSumOfDeltas=function(t,n,r=0){let o=e(t,n,r);if(!o)return null;let i=0,f=r-1;for(let t=0,e=o.length;t<e;++t){let e=o[t];i+=e-f-1,f=e}return{score:i,indices:o}},t.highlight=function(t,e,n){let r=[],o=0,i=0,f=e.length;for(;o<f;){let l=e[o],u=e[o];for(;++o<f&&e[o]===u+1;)u++;i<l&&r.push(t.slice(i,l)),l<u+1&&r.push(n(t.slice(l,u+1))),i=u+1}return i<t.length&&r.push(t.slice(i)),r},t.cmp=function(t,e){return t<e?-1:t>e?1:0}}(t.StringExt||(t.StringExt={})),t.chain=function*(...t){for(const e of t)for(const t of e)yield t},t.each=function(t,e){let n=0;for(const r of t)if(!1===e(r,n++))return},t.empty=function*(){},t.enumerate=function*(t,e=0){for(const n of t)yield[e++,n]},t.every=e,t.filter=function*(t,e){let n=0;for(const r of t)e(r,n++)&&(yield r)},t.find=function(t,e){let n=0;for(const r of t)if(e(r,n++))return r},t.findIndex=function(t,e){let n=0;for(const r of t)if(e(r,n++))return n-1;return-1},t.map=function*(t,e){let n=0;for(const r of t)yield e(r,n++)},t.max=function(t,e){let n;for(const r of t)void 0!==n?e(r,n)>0&&(n=r):n=r;return n},t.min=function(t,e){let n;for(const r of t)void 0!==n?e(r,n)<0&&(n=r):n=r;return n},t.minmax=function(t,e){let n,r,o=!0;for(const i of t)o?(n=i,r=i,o=!1):e(i,n)<0?n=i:e(i,r)>0&&(r=i);return o?void 0:[n,r]},t.once=function*(t){yield t},t.range=function*(t,e,r){void 0===e?(e=t,t=0,r=1):void 0===r&&(r=1);const o=n.rangeLength(t,e,r);for(let e=0;e<o;e++)yield t+r*e},t.reduce=function(t,e,n){const r=t[Symbol.iterator]();let o=0,i=r.next();if(i.done&&void 0===n)throw new TypeError("Reduce of empty iterable with no initial value.");if(i.done)return n;let f,l,u=r.next();if(u.done&&void 0===n)return i.value;if(u.done)return e(n,i.value,o++);for(f=e(void 0===n?i.value:e(n,i.value,o++),u.value,o++);!(l=r.next()).done;)f=e(f,l.value,o++);return f},t.repeat=function*(t,e){for(;0<e--;)yield t},t.retro=function(t){return"function"==typeof t.retro?t.retro():function*(t){for(let e=t.length-1;e>-1;e--)yield t[e]}(t)},t.some=function(t,e){let n=0;for(const r of t)if(e(r,n++))return!0;return!1},t.stride=function*(t,e){let n=0;for(const r of t)0==n++%e&&(yield r)},t.take=function*(t,e){if(e<1)return;const n=t[Symbol.iterator]();let r;for(;0<e--&&!(r=n.next()).done;)yield r.value},t.toArray=function(t){return Array.from(t)},t.toObject=function(t){const e={};for(const[n,r]of t)e[n]=r;return e},t.topologicSort=function(t){let e=[],n=new Set,r=new Map;for(const e of t)o(e);for(const[t]of r)i(t);return e;function o(t){let[e,n]=t,o=r.get(n);o?o.push(e):r.set(n,[e])}function i(t){if(n.has(t))return;n.add(t);let o=r.get(t);if(o)for(const t of o)i(t);e.push(t)}},t.zip=function*(...t){const n=t.map((t=>t[Symbol.iterator]()));let r=n.map((t=>t.next()));for(;e(r,(t=>!t.done));r=n.map((t=>t.next())))yield r.map((t=>t.value))},Object.defineProperty(t,"__esModule",{value:!0})}));
//# sourceMappingURL=index.min.js.map
{
"name": "@lumino/algorithm",
"version": "1.9.2",
"version": "2.0.0-alpha.0",
"description": "Lumino Algorithms and Iterators",

@@ -14,9 +14,3 @@ "homepage": "https://github.com/jupyterlab/lumino",

"license": "BSD-3-Clause",
"author": "S. Chris Colbert <sccolbert@gmail.com>",
"contributors": [
"A. T. Darian <git@darian.email>",
"Dave Willmer <dave.willmer@gmail.com>",
"S. Chris Colbert <sccolbert@gmail.com>",
"Steven Silvester <steven.silvester@gmail.com>"
],
"author": "Project Jupyter",
"main": "dist/index.js",

@@ -39,3 +33,2 @@ "jsdelivr": "dist/index.min.js",

"clean:test": "rimraf tests/build",
"docs": "typedoc --options tdoptions.json src",
"minimize": "terser dist/index.js -c -m --source-map \"content='dist/index.js.map',url='index.min.js.map'\" -o dist/index.min.js",

@@ -50,4 +43,9 @@ "test": "npm run test:firefox-headless",

},
"typedoc": {
"entryPoint": "./src/index.ts",
"displayName": "algorithm"
},
"devDependencies": {
"@microsoft/api-extractor": "^7.6.0",
"@rollup/plugin-node-resolve": "^13.3.0",
"@types/mocha": "^2.2.39",

@@ -62,13 +60,13 @@ "chai": "^4.3.4",

"mocha": "^9.0.3",
"postcss": "^8.4.14",
"rimraf": "^3.0.2",
"rollup": "^2.56.0",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-postcss": "^4.0.0",
"rollup": "^2.77.2",
"rollup-plugin-postcss": "^4.0.2",
"rollup-plugin-sourcemaps": "^0.6.3",
"terser": "^5.7.1",
"tslib": "^2.3.0",
"typedoc": "~0.15.0",
"typescript": "~3.6.0",
"webpack": "^4.41.3",
"webpack-cli": "^3.3.10"
"tslib": "^2.4.0",
"typedoc": "~0.23.9",
"typescript": "~4.7.3",
"webpack": "^5.74.0",
"webpack-cli": "^4.10.0"
},

@@ -75,0 +73,0 @@ "publishConfig": {

@@ -10,3 +10,2 @@ // Copyright (c) Jupyter Development Team.

|----------------------------------------------------------------------------*/
import { IIterator, iter, IterableOrArrayLike } from './iter';

@@ -16,3 +15,3 @@ /**

*
* @param objects - The iterable or array-like objects of interest.
* @param objects - The iterable objects of interest.
*

@@ -24,3 +23,3 @@ * @returns An iterator which yields the values of the iterables

* ```typescript
* import { chain, toArray } from '@lumino/algorithm';
* import { chain } from '@lumino/algorithm';
*

@@ -32,69 +31,11 @@ * let data1 = [1, 2, 3];

*
* toArray(stream); // [1, 2, 3, 4, 5, 6]
* Array.from(stream); // [1, 2, 3, 4, 5, 6]
* ```
*/
export function chain<T>(...objects: IterableOrArrayLike<T>[]): IIterator<T> {
return new ChainIterator<T>(iter(objects.map(iter)));
}
/**
* An iterator which chains together several iterators.
*/
export class ChainIterator<T> implements IIterator<T> {
/**
* Construct a new chain iterator.
*
* @param source - The iterator of iterators of interest.
*/
constructor(source: IIterator<IIterator<T>>) {
this._source = source;
this._active = undefined;
}
/**
* Get an iterator over the object's values.
*
* @returns An iterator which yields the object's values.
*/
iter(): IIterator<T> {
return this;
}
/**
* Create an independent clone of the iterator.
*
* @returns A new independent clone of the iterator.
*/
clone(): IIterator<T> {
let result = new ChainIterator<T>(this._source.clone());
result._active = this._active && this._active.clone();
result._cloned = true;
this._cloned = true;
return result;
}
/**
* Get the next value from the iterator.
*
* @returns The next value from the iterator, or `undefined`.
*/
next(): T | undefined {
if (this._active === undefined) {
let active = this._source.next();
if (active === undefined) {
return undefined;
}
this._active = this._cloned ? active.clone() : active;
export function* chain<T>(...objects: Iterable<T>[]): IterableIterator<T> {
for (const object of objects) {
for (const value of object) {
yield value;
}
let value = this._active.next();
if (value !== undefined) {
return value;
}
this._active = undefined;
return this.next();
}
private _source: IIterator<IIterator<T>>;
private _active: IIterator<T> | undefined;
private _cloned = false;
}

@@ -10,3 +10,2 @@ // Copyright (c) Jupyter Development Team.

|----------------------------------------------------------------------------*/
import { IIterator } from './iter';

@@ -20,43 +19,12 @@ /**

* ```typescript
* import { empty, toArray } from '@lumino/algorithm';
* import { empty } from '@lumino/algorithm';
*
* let stream = empty<number>();
*
* toArray(stream); // []
* Array.from(stream); // []
* ```
*/
export function empty<T>(): IIterator<T> {
return new EmptyIterator<T>();
// eslint-disable-next-line require-yield, @typescript-eslint/no-unused-vars
export function* empty<T>(): IterableIterator<T> {
return;
}
/**
* An iterator which is always empty.
*/
export class EmptyIterator<T> implements IIterator<T> {
/**
* Get an iterator over the object's values.
*
* @returns An iterator which yields the object's values.
*/
iter(): IIterator<T> {
return this;
}
/**
* Create an independent clone of the iterator.
*
* @returns A new independent clone of the iterator.
*/
clone(): IIterator<T> {
return new EmptyIterator<T>();
}
/**
* Get the next value from the iterator.
*
* @returns The next value from the iterator, or `undefined`.
*/
next(): T | undefined {
return undefined;
}
}

@@ -10,3 +10,2 @@ // Copyright (c) Jupyter Development Team.

|----------------------------------------------------------------------------*/
import { IIterator, iter, IterableOrArrayLike } from './iter';

@@ -16,3 +15,3 @@ /**

*
* @param object - The iterable or array-like object of interest.
* @param object - The iterable object of interest.
*

@@ -25,3 +24,3 @@ * @param start - The starting enum value. The default is `0`.

* ```typescript
* import { enumerate, toArray } from '@lumino/algorithm';
* import { enumerate } from '@lumino/algorithm';
*

@@ -32,61 +31,12 @@ * let data = ['foo', 'bar', 'baz'];

*
* toArray(stream); // [[1, 'foo'], [2, 'bar'], [3, 'baz']]
* Array.from(stream); // [[1, 'foo'], [2, 'bar'], [3, 'baz']]
* ```
*/
export function enumerate<T>(
object: IterableOrArrayLike<T>,
export function* enumerate<T>(
object: Iterable<T>,
start = 0
): IIterator<[number, T]> {
return new EnumerateIterator<T>(iter(object), start);
}
/**
* An iterator which enumerates the source values.
*/
export class EnumerateIterator<T> implements IIterator<[number, T]> {
/**
* Construct a new enumerate iterator.
*
* @param source - The iterator of values of interest.
*
* @param start - The starting enum value.
*/
constructor(source: IIterator<T>, start: number) {
this._source = source;
this._index = start;
): IterableIterator<[number, T]> {
for (const value of object) {
yield [start++, value];
}
/**
* Get an iterator over the object's values.
*
* @returns An iterator which yields the object's values.
*/
iter(): IIterator<[number, T]> {
return this;
}
/**
* Create an independent clone of the iterator.
*
* @returns A new independent clone of the iterator.
*/
clone(): IIterator<[number, T]> {
return new EnumerateIterator<T>(this._source.clone(), this._index);
}
/**
* Get the next value from the iterator.
*
* @returns The next value from the iterator, or `undefined`.
*/
next(): [number, T] | undefined {
let value = this._source.next();
if (value === undefined) {
return undefined;
}
return [this._index++, value];
}
private _source: IIterator<T>;
private _index: number;
}

@@ -10,3 +10,2 @@ // Copyright (c) Jupyter Development Team.

|----------------------------------------------------------------------------*/
import { IIterator, iter, IterableOrArrayLike } from './iter';

@@ -16,3 +15,3 @@ /**

*
* @param object - The iterable or array-like object of interest.
* @param object - The iterable object of interest.
*

@@ -25,3 +24,3 @@ * @param fn - The predicate function to invoke for each value.

* ```typescript
* import { filter, toArray } from '@lumino/algorithm';
* import { filter } from '@lumino/algorithm';
*

@@ -32,68 +31,15 @@ * let data = [1, 2, 3, 4, 5, 6];

*
* toArray(stream); // [2, 4, 6]
* Array.from(stream); // [2, 4, 6]
* ```
*/
export function filter<T>(
object: IterableOrArrayLike<T>,
export function* filter<T>(
object: Iterable<T>,
fn: (value: T, index: number) => boolean
): IIterator<T> {
return new FilterIterator<T>(iter(object), fn);
}
/**
* An iterator which yields values which pass a test.
*/
export class FilterIterator<T> implements IIterator<T> {
/**
* Construct a new filter iterator.
*
* @param source - The iterator of values of interest.
*
* @param fn - The predicate function to invoke for each value.
*/
constructor(source: IIterator<T>, fn: (value: T, index: number) => boolean) {
this._source = source;
this._fn = fn;
}
/**
* Get an iterator over the object's values.
*
* @returns An iterator which yields the object's values.
*/
iter(): IIterator<T> {
return this;
}
/**
* Create an independent clone of the iterator.
*
* @returns A new independent clone of the iterator.
*/
clone(): IIterator<T> {
let result = new FilterIterator<T>(this._source.clone(), this._fn);
result._index = this._index;
return result;
}
/**
* Get the next value from the iterator.
*
* @returns The next value from the iterator, or `undefined`.
*/
next(): T | undefined {
let fn = this._fn;
let it = this._source;
let value: T | undefined;
while ((value = it.next()) !== undefined) {
if (fn(value, this._index++)) {
return value;
}
): IterableIterator<T> {
let index = 0;
for (const value of object) {
if (fn(value, index++)) {
yield value;
}
return undefined;
}
private _index = 0;
private _source: IIterator<T>;
private _fn: (value: T, index: number) => boolean;
}

@@ -10,3 +10,2 @@ // Copyright (c) Jupyter Development Team.

|----------------------------------------------------------------------------*/
import { iter, IterableOrArrayLike } from './iter';

@@ -16,3 +15,3 @@ /**

*
* @param object - The iterable or array-like object to search.
* @param object - The iterable object to search.
*

@@ -47,9 +46,7 @@ * @param fn - The predicate function to apply to the values.

export function find<T>(
object: IterableOrArrayLike<T>,
object: Iterable<T>,
fn: (value: T, index: number) => boolean
): T | undefined {
let index = 0;
let it = iter(object);
let value: T | undefined;
while ((value = it.next()) !== undefined) {
for (const value of object) {
if (fn(value, index++)) {

@@ -65,3 +62,3 @@ return value;

*
* @param object - The iterable or array-like object to search.
* @param object - The iterable object to search.
*

@@ -96,9 +93,7 @@ * @param fn - The predicate function to apply to the values.

export function findIndex<T>(
object: IterableOrArrayLike<T>,
object: Iterable<T>,
fn: (value: T, index: number) => boolean
): number {
let index = 0;
let it = iter(object);
let value: T | undefined;
while ((value = it.next()) !== undefined) {
for (const value of object) {
if (fn(value, index++)) {

@@ -114,3 +109,3 @@ return index - 1;

*
* @param object - The iterable or array-like object to search.
* @param object - The iterable object to search.
*

@@ -141,12 +136,11 @@ * @param fn - The 3-way comparison function to apply to the values.

export function min<T>(
object: IterableOrArrayLike<T>,
object: Iterable<T>,
fn: (first: T, second: T) => number
): T | undefined {
let it = iter(object);
let value = it.next();
if (value === undefined) {
return undefined;
}
let result = value;
while ((value = it.next()) !== undefined) {
let result: T | undefined = undefined;
for (const value of object) {
if (result === undefined) {
result = value;
continue;
}
if (fn(value, result) < 0) {

@@ -162,3 +156,3 @@ result = value;

*
* @param object - The iterable or array-like object to search.
* @param object - The iterable object to search.
*

@@ -189,12 +183,11 @@ * @param fn - The 3-way comparison function to apply to the values.

export function max<T>(
object: IterableOrArrayLike<T>,
object: Iterable<T>,
fn: (first: T, second: T) => number
): T | undefined {
let it = iter(object);
let value = it.next();
if (value === undefined) {
return undefined;
}
let result = value;
while ((value = it.next()) !== undefined) {
let result: T | undefined = undefined;
for (const value of object) {
if (result === undefined) {
result = value;
continue;
}
if (fn(value, result) > 0) {

@@ -210,3 +203,3 @@ result = value;

*
* @param object - The iterable or array-like object to search.
* @param object - The iterable object to search.
*

@@ -237,20 +230,20 @@ * @param fn - The 3-way comparison function to apply to the values.

export function minmax<T>(
object: IterableOrArrayLike<T>,
object: Iterable<T>,
fn: (first: T, second: T) => number
): [T, T] | undefined {
let it = iter(object);
let value = it.next();
if (value === undefined) {
return undefined;
}
let vmin = value;
let vmax = value;
while ((value = it.next()) !== undefined) {
if (fn(value, vmin) < 0) {
let empty = true;
let vmin: T;
let vmax: T;
for (const value of object) {
if (empty) {
vmin = value;
} else if (fn(value, vmax) > 0) {
vmax = value;
empty = false;
} else if (fn(value, vmin!) < 0) {
vmin = value;
} else if (fn(value, vmax!) > 0) {
vmax = value;
}
}
return [vmin, vmax];
return empty ? undefined : [vmin!, vmax!];
}

@@ -12,190 +12,53 @@ // Copyright (c) Jupyter Development Team.

/**
* An object which can produce an iterator over its values.
*/
export interface IIterable<T> {
/**
* Get an iterator over the object's values.
*
* @returns An iterator which yields the object's values.
*
* #### Notes
* Depending on the iterable, the returned iterator may or may not be
* a new object. A collection or other container-like object should
* typically return a new iterator, while an iterator itself should
* normally return `this`.
*/
iter(): IIterator<T>;
}
/**
* An object which traverses a collection of values.
* Create an array from an iterable of values.
*
* #### Notes
* An `IIterator` is itself an `IIterable`. Most implementations of
* `IIterator` should simply return `this` from the `iter()` method.
*/
export interface IIterator<T> extends IIterable<T> {
/**
* Create an independent clone of the iterator.
*
* @returns A new independent clone of the iterator.
*
* #### Notes
* The cloned iterator can be consumed independently of the current
* iterator. In essence, it is a copy of the iterator value stream
* which starts at the current location.
*
* This can be useful for lookahead and stream duplication.
*/
clone(): IIterator<T>;
/**
* Get the next value from the iterator.
*
* @returns The next value from the iterator, or `undefined`.
*
* #### Notes
* The `undefined` value is used to signal the end of iteration and
* should therefore not be used as a value in a collection.
*
* The use of the `undefined` sentinel is an explicit design choice
* which favors performance over purity. The ES6 iterator design of
* returning a `{ value, done }` pair is suboptimal, as it requires
* an object allocation on each iteration; and an `isDone()` method
* would increase implementation and runtime complexity.
*/
next(): T | undefined;
}
/**
* A type alias for an iterable or builtin array-like object.
*/
export type IterableOrArrayLike<T> = IIterable<T> | ArrayLike<T>;
/**
* Create an iterator for an iterable object.
* @deprecated
*
* @param object - The iterable or array-like object of interest.
*
* @returns A new iterator for the given object.
* @returns A new array of values from the given object.
*
* #### Notes
* This function allows iteration algorithms to operate on user-defined
* iterable types and builtin array-like objects in a uniform fashion.
*/
export function iter<T>(object: IterableOrArrayLike<T>): IIterator<T> {
let it: IIterator<T>;
if (typeof (object as any).iter === 'function') {
it = (object as IIterable<T>).iter();
} else {
it = new ArrayIterator<T>(object as ArrayLike<T>);
}
return it;
}
/**
* Create an iterator for the keys in an object.
*
* @param object - The object of interest.
*
* @returns A new iterator for the keys in the given object.
*
* #### Complexity
* Linear.
*
* #### Example
* ```typescript
* import { each, keys } from '@lumino/algorithm';
* import { toArray } from '@lumino/algorithm';
*
* let data = { one: 1, two: 2, three: 3 };
* let stream = [1, 2, 3, 4, 5, 6][Symbol.iterator]();
*
* each(keys(data), key => { console.log(key); }); // 'one', 'two', 'three'
* toArray(stream); // [1, 2, 3, 4, 5, 6];
* ```
*/
export function iterKeys<T>(object: {
readonly [key: string]: T;
}): IIterator<string> {
return new KeyIterator(object);
export function toArray<T>(object: Iterable<T>): T[] {
return Array.from(object);
}
/**
* Create an iterator for the values in an object.
* Create an object from an iterable of key/value pairs.
*
* @param object - The object of interest.
* @param object - The iterable or array-like object of interest.
*
* @returns A new iterator for the values in the given object.
* @returns A new object mapping keys to values.
*
* #### Complexity
* Linear.
*
* #### Example
* ```typescript
* import { each, values } from '@lumino/algorithm';
* import { toObject } from '@lumino/algorithm';
*
* let data = { one: 1, two: 2, three: 3 };
* let data: [string, number][] = [['one', 1], ['two', 2], ['three', 3]];
*
* each(values(data), value => { console.log(value); }); // 1, 2, 3
* toObject(data); // { one: 1, two: 2, three: 3 }
* ```
*/
export function iterValues<T>(object: {
readonly [key: string]: T;
}): IIterator<T> {
return new ValueIterator<T>(object);
export function toObject<T>(object: Iterable<[string, T]>): {
[key: string]: T;
} {
const result: { [key: string]: T } = {};
for (const [key, value] of object) {
result[key] = value;
}
return result;
}
/**
* Create an iterator for the items in an object.
*
* @param object - The object of interest.
*
* @returns A new iterator for the items in the given object.
*
* #### Complexity
* Linear.
*
* #### Example
* ```typescript
* import { each, items } from '@lumino/algorithm';
*
* let data = { one: 1, two: 2, three: 3 };
*
* each(items(data), value => { console.log(value); }); // ['one', 1], ['two', 2], ['three', 3]
* ```
*/
export function iterItems<T>(object: {
readonly [key: string]: T;
}): IIterator<[string, T]> {
return new ItemIterator<T>(object);
}
/**
* Create an iterator for an iterator-like function.
*
* @param fn - A function which behaves like an iterator `next` method.
*
* @returns A new iterator for the given function.
*
* #### Notes
* The returned iterator **cannot** be cloned.
*
* #### Example
* ```typescript
* import { each, iterFn } from '@lumino/algorithm';
*
* let it = iterFn((() => {
* let i = 0;
* return () => i > 3 ? undefined : i++;
* })());
*
* each(it, v => { console.log(v); }); // 0, 1, 2, 3
* ```
*/
export function iterFn<T>(fn: () => T | undefined): IIterator<T> {
return new FnIterator<T>(fn);
}
/**
* Invoke a function for each value in an iterable.
*
* @param object - The iterable or array-like object of interest.
* @param object - The iterable object of interest.
*

@@ -221,10 +84,8 @@ * @param fn - The callback function to invoke for each value.

export function each<T>(
object: IterableOrArrayLike<T>,
object: Iterable<T>,
fn: (value: T, index: number) => boolean | void
): void {
let index = 0;
let it = iter(object);
let value: T | undefined;
while ((value = it.next()) !== undefined) {
if (fn(value, index++) === false) {
for (const value of object) {
if (false === fn(value, index++)) {
return;

@@ -238,3 +99,3 @@ }

*
* @param object - The iterable or array-like object of interest.
* @param object - The iterable object of interest.
*

@@ -262,10 +123,8 @@ * @param fn - The predicate function to invoke for each value.

export function every<T>(
object: IterableOrArrayLike<T>,
object: Iterable<T>,
fn: (value: T, index: number) => boolean
): boolean {
let index = 0;
let it = iter(object);
let value: T | undefined;
while ((value = it.next()) !== undefined) {
if (!fn(value, index++)) {
for (const value of object) {
if (false === fn(value, index++)) {
return false;

@@ -280,3 +139,3 @@ }

*
* @param object - The iterable or array-like object of interest.
* @param object - The iterable object of interest.
*

@@ -304,9 +163,7 @@ * @param fn - The predicate function to invoke for each value.

export function some<T>(
object: IterableOrArrayLike<T>,
object: Iterable<T>,
fn: (value: T, index: number) => boolean
): boolean {
let index = 0;
let it = iter(object);
let value: T | undefined;
while ((value = it.next()) !== undefined) {
for (const value of object) {
if (fn(value, index++)) {

@@ -318,342 +175,1 @@ return true;

}
/**
* Create an array from an iterable of values.
*
* @param object - The iterable or array-like object of interest.
*
* @returns A new array of values from the given object.
*
* #### Example
* ```typescript
* import { iter, toArray } from '@lumino/algorithm';
*
* let data = [1, 2, 3, 4, 5, 6];
*
* let stream = iter(data);
*
* toArray(stream); // [1, 2, 3, 4, 5, 6];
* ```
*/
export function toArray<T>(object: IterableOrArrayLike<T>): T[] {
let index = 0;
let result: T[] = [];
let it = iter(object);
let value: T | undefined;
while ((value = it.next()) !== undefined) {
result[index++] = value;
}
return result;
}
/**
* Create an object from an iterable of key/value pairs.
*
* @param object - The iterable or array-like object of interest.
*
* @returns A new object mapping keys to values.
*
* #### Example
* ```typescript
* import { toObject } from '@lumino/algorithm';
*
* let data = [['one', 1], ['two', 2], ['three', 3]];
*
* toObject(data); // { one: 1, two: 2, three: 3 }
* ```
*/
export function toObject<T>(
object: IterableOrArrayLike<[string, T]>
): { [key: string]: T } {
let it = iter(object);
let pair: [string, T] | undefined;
let result: { [key: string]: T } = {};
while ((pair = it.next()) !== undefined) {
result[pair[0]] = pair[1];
}
return result;
}
/**
* An iterator for an array-like object.
*
* #### Notes
* This iterator can be used for any builtin JS array-like object.
*/
export class ArrayIterator<T> implements IIterator<T> {
/**
* Construct a new array iterator.
*
* @param source - The array-like object of interest.
*/
constructor(source: ArrayLike<T>) {
this._source = source;
}
/**
* Get an iterator over the object's values.
*
* @returns An iterator which yields the object's values.
*/
iter(): IIterator<T> {
return this;
}
/**
* Create an independent clone of the iterator.
*
* @returns A new independent clone of the iterator.
*/
clone(): IIterator<T> {
let result = new ArrayIterator<T>(this._source);
result._index = this._index;
return result;
}
/**
* Get the next value from the iterator.
*
* @returns The next value from the iterator, or `undefined`.
*/
next(): T | undefined {
if (this._index >= this._source.length) {
return undefined;
}
return this._source[this._index++];
}
private _index = 0;
private _source: ArrayLike<T>;
}
/**
* An iterator for the keys in an object.
*
* #### Notes
* This iterator can be used for any JS object.
*/
export class KeyIterator implements IIterator<string> {
/**
* Construct a new key iterator.
*
* @param source - The object of interest.
*
* @param keys - The keys to iterate, if known.
*/
constructor(
source: { readonly [key: string]: any },
keys = Object.keys(source)
) {
this._source = source;
this._keys = keys;
}
/**
* Get an iterator over the object's values.
*
* @returns An iterator which yields the object's values.
*/
iter(): IIterator<string> {
return this;
}
/**
* Create an independent clone of the iterator.
*
* @returns A new independent clone of the iterator.
*/
clone(): IIterator<string> {
let result = new KeyIterator(this._source, this._keys);
result._index = this._index;
return result;
}
/**
* Get the next value from the iterator.
*
* @returns The next value from the iterator, or `undefined`.
*/
next(): string | undefined {
if (this._index >= this._keys.length) {
return undefined;
}
let key = this._keys[this._index++];
if (key in this._source) {
return key;
}
return this.next();
}
private _index = 0;
private _keys: string[];
private _source: { readonly [key: string]: any };
}
/**
* An iterator for the values in an object.
*
* #### Notes
* This iterator can be used for any JS object.
*/
export class ValueIterator<T> implements IIterator<T> {
/**
* Construct a new value iterator.
*
* @param source - The object of interest.
*
* @param keys - The keys to iterate, if known.
*/
constructor(
source: { readonly [key: string]: T },
keys = Object.keys(source)
) {
this._source = source;
this._keys = keys;
}
/**
* Get an iterator over the object's values.
*
* @returns An iterator which yields the object's values.
*/
iter(): IIterator<T> {
return this;
}
/**
* Create an independent clone of the iterator.
*
* @returns A new independent clone of the iterator.
*/
clone(): IIterator<T> {
let result = new ValueIterator<T>(this._source, this._keys);
result._index = this._index;
return result;
}
/**
* Get the next value from the iterator.
*
* @returns The next value from the iterator, or `undefined`.
*/
next(): T | undefined {
if (this._index >= this._keys.length) {
return undefined;
}
let key = this._keys[this._index++];
if (key in this._source) {
return this._source[key];
}
return this.next();
}
private _index = 0;
private _keys: string[];
private _source: { readonly [key: string]: T };
}
/**
* An iterator for the items in an object.
*
* #### Notes
* This iterator can be used for any JS object.
*/
export class ItemIterator<T> implements IIterator<[string, T]> {
/**
* Construct a new item iterator.
*
* @param source - The object of interest.
*
* @param keys - The keys to iterate, if known.
*/
constructor(
source: { readonly [key: string]: T },
keys = Object.keys(source)
) {
this._source = source;
this._keys = keys;
}
/**
* Get an iterator over the object's values.
*
* @returns An iterator which yields the object's values.
*/
iter(): IIterator<[string, T]> {
return this;
}
/**
* Create an independent clone of the iterator.
*
* @returns A new independent clone of the iterator.
*/
clone(): IIterator<[string, T]> {
let result = new ItemIterator<T>(this._source, this._keys);
result._index = this._index;
return result;
}
/**
* Get the next value from the iterator.
*
* @returns The next value from the iterator, or `undefined`.
*/
next(): [string, T] | undefined {
if (this._index >= this._keys.length) {
return undefined;
}
let key = this._keys[this._index++];
if (key in this._source) {
return [key, this._source[key]];
}
return this.next();
}
private _index = 0;
private _keys: string[];
private _source: { readonly [key: string]: T };
}
/**
* An iterator for an iterator-like function.
*/
export class FnIterator<T> implements IIterator<T> {
/**
* Construct a new function iterator.
*
* @param fn - The iterator-like function of interest.
*/
constructor(fn: () => T | undefined) {
this._fn = fn;
}
/**
* Get an iterator over the object's values.
*
* @returns An iterator which yields the object's values.
*/
iter(): IIterator<T> {
return this;
}
/**
* Create an independent clone of the iterator.
*
* @returns A new independent clone of the iterator.
*/
clone(): IIterator<T> {
throw new Error('An `FnIterator` cannot be cloned.');
}
/**
* Get the next value from the iterator.
*
* @returns The next value from the iterator, or `undefined`.
*/
next(): T | undefined {
return this._fn.call(undefined);
}
private _fn: () => T | undefined;
}

@@ -10,8 +10,6 @@ // Copyright (c) Jupyter Development Team.

|----------------------------------------------------------------------------*/
import { IIterator, iter, IterableOrArrayLike } from './iter';
/**
* Transform the values of an iterable with a mapping function.
*
* @param object - The iterable or array-like object of interest.
* @param object - The iterable object of interest.
*

@@ -24,3 +22,3 @@ * @param fn - The mapping function to invoke for each value.

* ```typescript
* import { map, toArray } from '@lumino/algorithm';
* import { map } from '@lumino/algorithm';
*

@@ -31,64 +29,13 @@ * let data = [1, 2, 3];

*
* toArray(stream); // [2, 4, 6]
* Array.from(stream); // [2, 4, 6]
* ```
*/
export function map<T, U>(
object: IterableOrArrayLike<T>,
export function* map<T, U>(
object: Iterable<T>,
fn: (value: T, index: number) => U
): IIterator<U> {
return new MapIterator<T, U>(iter(object), fn);
}
/**
* An iterator which transforms values using a mapping function.
*/
export class MapIterator<T, U> implements IIterator<U> {
/**
* Construct a new map iterator.
*
* @param source - The iterator of values of interest.
*
* @param fn - The mapping function to invoke for each value.
*/
constructor(source: IIterator<T>, fn: (value: T, index: number) => U) {
this._source = source;
this._fn = fn;
): IterableIterator<U> {
let index = 0;
for (const value of object) {
yield fn(value, index++);
}
/**
* Get an iterator over the object's values.
*
* @returns An iterator which yields the object's values.
*/
iter(): IIterator<U> {
return this;
}
/**
* Create an independent clone of the iterator.
*
* @returns A new independent clone of the iterator.
*/
clone(): IIterator<U> {
let result = new MapIterator<T, U>(this._source.clone(), this._fn);
result._index = this._index;
return result;
}
/**
* Get the next value from the iterator.
*
* @returns The next value from the iterator, or `undefined`.
*/
next(): U | undefined {
let value = this._source.next();
if (value === undefined) {
return undefined;
}
return this._fn.call(undefined, value, this._index++);
}
private _index = 0;
private _source: IIterator<T>;
private _fn: (value: T, index: number) => U;
}

@@ -10,4 +10,2 @@ // Copyright (c) Jupyter Development Team.

|----------------------------------------------------------------------------*/
import { IIterator } from './iter';
/**

@@ -30,77 +28,31 @@ * Create an iterator of evenly spaced values.

* to `1`.
*
* #### Example
* ```typescript
* import { range } from '@lumino/algorithm';
*
* let stream = range(2, 4);
*
* Array.from(stream); // [2, 3]
* ```
*/
export function range(
export function* range(
start: number,
stop?: number,
step?: number
): IIterator<number> {
): IterableIterator<number> {
if (stop === undefined) {
return new RangeIterator(0, start, 1);
stop = start;
start = 0;
step = 1;
} else if (step === undefined) {
step = 1;
}
if (step === undefined) {
return new RangeIterator(start, stop, 1);
const length = Private.rangeLength(start, stop, step);
for (let index = 0; index < length; index++) {
yield start + step * index;
}
return new RangeIterator(start, stop, step);
}
/**
* An iterator which produces a range of evenly spaced values.
*/
export class RangeIterator implements IIterator<number> {
/**
* Construct a new range iterator.
*
* @param start - The starting value for the range, inclusive.
*
* @param stop - The stopping value for the range, exclusive.
*
* @param step - The distance between each value.
*/
constructor(start: number, stop: number, step: number) {
this._start = start;
this._stop = stop;
this._step = step;
this._length = Private.rangeLength(start, stop, step);
}
/**
* Get an iterator over the object's values.
*
* @returns An iterator which yields the object's values.
*/
iter(): IIterator<number> {
return this;
}
/**
* Create an independent clone of the iterator.
*
* @returns A new independent clone of the iterator.
*/
clone(): IIterator<number> {
let result = new RangeIterator(this._start, this._stop, this._step);
result._index = this._index;
return result;
}
/**
* Get the next value from the iterator.
*
* @returns The next value from the iterator, or `undefined`.
*/
next(): number | undefined {
if (this._index >= this._length) {
return undefined;
}
return this._start + this._step * this._index++;
}
private _index = 0;
private _length: number;
private _start: number;
private _stop: number;
private _step: number;
}
/**
* The namespace for the module implementation details.

@@ -107,0 +59,0 @@ */

@@ -10,3 +10,2 @@ // Copyright (c) Jupyter Development Team.

|----------------------------------------------------------------------------*/
import { iter, IterableOrArrayLike } from './iter';

@@ -16,3 +15,3 @@ /**

*
* @param object - The iterable or array-like object of interest.
* @param object - The iterable object of interest.
*

@@ -52,7 +51,7 @@ * @param fn - The reducer function to invoke for each value.

export function reduce<T>(
object: IterableOrArrayLike<T>,
object: Iterable<T>,
fn: (accumulator: T, value: T, index: number) => T
): T;
export function reduce<T, U>(
object: IterableOrArrayLike<T>,
object: Iterable<T>,
fn: (accumulator: U, value: T, index: number) => U,

@@ -62,13 +61,13 @@ initial: U

export function reduce<T>(
object: IterableOrArrayLike<T>,
object: Iterable<T>,
fn: (accumulator: any, value: T, index: number) => any,
initial?: any
initial?: unknown
): any {
// Setup the iterator and fetch the first value.
const it = object[Symbol.iterator]();
let index = 0;
let it = iter(object);
let first = it.next();
// An empty iterator and no initial value is an error.
if (first === undefined && initial === undefined) {
if (first.done && initial === undefined) {
throw new TypeError('Reduce of empty iterable with no initial value.');

@@ -78,3 +77,3 @@ }

// If the iterator is empty, return the initial value.
if (first === undefined) {
if (first.done) {
return initial;

@@ -86,4 +85,4 @@ }

let second = it.next();
if (second === undefined && initial === undefined) {
return first;
if (second.done && initial === undefined) {
return first.value;
}

@@ -93,4 +92,4 @@

// the reducer is invoked and that result is the return value.
if (second === undefined) {
return fn(initial, first, index++);
if (second.done) {
return fn(initial, first.value, index++);
}

@@ -101,11 +100,11 @@

if (initial === undefined) {
accumulator = fn(first, second, index++);
accumulator = fn(first.value, second.value, index++);
} else {
accumulator = fn(fn(initial, first, index++), second, index++);
accumulator = fn(fn(initial, first.value, index++), second.value, index++);
}
// Iterate the rest of the values, updating the accumulator.
let next: T | undefined;
while ((next = it.next()) !== undefined) {
accumulator = fn(accumulator, next, index++);
let next: IteratorResult<T>;
while (!(next = it.next()).done) {
accumulator = fn(accumulator, next.value, index++);
}

@@ -112,0 +111,0 @@

@@ -10,3 +10,2 @@ // Copyright (c) Jupyter Development Team.

|----------------------------------------------------------------------------*/
import { IIterator } from './iter';

@@ -24,11 +23,13 @@ /**

* ```typescript
* import { repeat, toArray } from '@lumino/algorithm';
* import { repeat } from '@lumino/algorithm';
*
* let stream = repeat(7, 3);
*
* toArray(stream); // [7, 7, 7]
* Array.from(stream); // [7, 7, 7]
* ```
*/
export function repeat<T>(value: T, count: number): IIterator<T> {
return new RepeatIterator<T>(value, count);
export function* repeat<T>(value: T, count: number): IterableIterator<T> {
while (0 < count--) {
yield value;
}
}

@@ -45,62 +46,11 @@

* ```typescript
* import { once, toArray } from '@lumino/algorithm';
* import { once } from '@lumino/algorithm';
*
* let stream = once(7);
*
* toArray(stream); // [7]
* Array.from(stream); // [7]
* ```
*/
export function once<T>(value: T): IIterator<T> {
return new RepeatIterator<T>(value, 1);
export function* once<T>(value: T): IterableIterator<T> {
yield value;
}
/**
* An iterator which repeats a value a specified number of times.
*/
export class RepeatIterator<T> implements IIterator<T> {
/**
* Construct a new repeat iterator.
*
* @param value - The value to repeat.
*
* @param count - The number of times to repeat the value.
*/
constructor(value: T, count: number) {
this._value = value;
this._count = count;
}
/**
* Get an iterator over the object's values.
*
* @returns An iterator which yields the object's values.
*/
iter(): IIterator<T> {
return this;
}
/**
* Create an independent clone of the iterator.
*
* @returns A new independent clone of the iterator.
*/
clone(): IIterator<T> {
return new RepeatIterator<T>(this._value, this._count);
}
/**
* Get the next value from the iterator.
*
* @returns The next value from the iterator, or `undefined`.
*/
next(): T | undefined {
if (this._count <= 0) {
return undefined;
}
this._count--;
return this._value;
}
private _value: T;
private _count: number;
}

@@ -10,3 +10,2 @@ // Copyright (c) Jupyter Development Team.

|----------------------------------------------------------------------------*/
import { IIterator } from './iter';

@@ -22,11 +21,6 @@ /**

*/
retro(): IIterator<T>;
retro(): IterableIterator<T>;
}
/**
* A type alias for a retroable or builtin array-like object.
*/
export type RetroableOrArrayLike<T> = IRetroable<T> | ArrayLike<T>;
/**
* Create an iterator for a retroable object.

@@ -40,3 +34,3 @@ *

* ```typescript
* import { retro, toArray } from '@lumino/algorithm';
* import { retro } from '@lumino/algorithm';
*

@@ -47,66 +41,16 @@ * let data = [1, 2, 3, 4, 5, 6];

*
* toArray(stream); // [6, 5, 4, 3, 2, 1]
* Array.from(stream); // [6, 5, 4, 3, 2, 1]
* ```
*/
export function retro<T>(object: RetroableOrArrayLike<T>): IIterator<T> {
let it: IIterator<T>;
export function retro<T>(
object: IRetroable<T> | ArrayLike<T>
): IterableIterator<T> {
if (typeof (object as any).retro === 'function') {
it = (object as IRetroable<T>).retro();
} else {
it = new RetroArrayIterator<T>(object as ArrayLike<T>);
return (object as IRetroable<T>).retro();
}
return it;
}
/**
* An iterator which traverses an array-like object in reverse.
*
* #### Notes
* This iterator can be used for any builtin JS array-like object.
*/
export class RetroArrayIterator<T> implements IIterator<T> {
/**
* Construct a new retro iterator.
*
* @param source - The array-like object of interest.
*/
constructor(source: ArrayLike<T>) {
this._source = source;
this._index = source.length - 1;
}
/**
* Get an iterator over the object's values.
*
* @returns An iterator which yields the object's values.
*/
iter(): IIterator<T> {
return this;
}
/**
* Create an independent clone of the iterator.
*
* @returns A new independent clone of the iterator.
*/
clone(): IIterator<T> {
let result = new RetroArrayIterator<T>(this._source);
result._index = this._index;
return result;
}
/**
* Get the next value from the iterator.
*
* @returns The next value from the iterator, or `undefined`.
*/
next(): T | undefined {
if (this._index < 0 || this._index >= this._source.length) {
return undefined;
return (function* (object) {
for (let index = object.length - 1; index > -1; index--) {
yield object[index];
}
return this._source[this._index--];
}
private _index: number;
private _source: ArrayLike<T>;
})(object as ArrayLike<T>);
}

@@ -10,3 +10,2 @@ // Copyright (c) Jupyter Development Team.

|----------------------------------------------------------------------------*/
import { each, IterableOrArrayLike } from './iter';

@@ -16,3 +15,3 @@ /**

*
* @param edges - The iterable or array-like object of edges to sort.
* @param edges - The iterable object of edges to sort.
* An edge is represented as a 2-tuple of `[fromNode, toNode]`.

@@ -40,3 +39,3 @@ *

*/
export function topologicSort<T>(edges: IterableOrArrayLike<[T, T]>): T[] {
export function topologicSort<T>(edges: Iterable<[T, T]>): T[] {
// Setup the shared sorting state.

@@ -48,8 +47,10 @@ let sorted: T[] = [];

// Add the edges to the graph.
each(edges, addEdge);
for (const edge of edges) {
addEdge(edge);
}
// Visit each node in the graph.
graph.forEach((v, k) => {
for (const [k] of graph) {
visit(k);
});
}

@@ -78,3 +79,5 @@ // Return the sorted results.

if (children) {
children.forEach(visit);
for (const child of children) {
visit(child);
}
}

@@ -81,0 +84,0 @@ sorted.push(node);

@@ -10,3 +10,2 @@ // Copyright (c) Jupyter Development Team.

|----------------------------------------------------------------------------*/
import { IIterator, iter, IterableOrArrayLike } from './iter';

@@ -16,3 +15,3 @@ /**

*
* @param object - The iterable or array-like object of interest.
* @param object - The iterable object of interest.
*

@@ -26,3 +25,3 @@ * @param step - The distance to step on each iteration. A value

* ```typescript
* import { stride, toArray } from '@lumino/algorithm';
* import { stride } from '@lumino/algorithm';
*

@@ -33,62 +32,15 @@ * let data = [1, 2, 3, 4, 5, 6];

*
* toArray(stream); // [1, 3, 5];
* Array.from(stream); // [1, 3, 5];
* ```
*/
export function stride<T>(
object: IterableOrArrayLike<T>,
export function* stride<T>(
object: Iterable<T>,
step: number
): IIterator<T> {
return new StrideIterator<T>(iter(object), step);
}
/**
* An iterator which traverses a source iterator step-wise.
*/
export class StrideIterator<T> implements IIterator<T> {
/**
* Construct a new stride iterator.
*
* @param source - The iterator of values of interest.
*
* @param step - The distance to step on each iteration. A value
* of less than `1` will behave the same as a value of `1`.
*/
constructor(source: IIterator<T>, step: number) {
this._source = source;
this._step = step;
}
/**
* Get an iterator over the object's values.
*
* @returns An iterator which yields the object's values.
*/
iter(): IIterator<T> {
return this;
}
/**
* Create an independent clone of the iterator.
*
* @returns A new independent clone of the iterator.
*/
clone(): IIterator<T> {
return new StrideIterator<T>(this._source.clone(), this._step);
}
/**
* Get the next value from the iterator.
*
* @returns The next value from the iterator, or `undefined`.
*/
next(): T | undefined {
let value = this._source.next();
for (let n = this._step - 1; n > 0; --n) {
this._source.next();
): IterableIterator<T> {
let count = 0;
for (const value of object) {
if (0 === count++ % step) {
yield value;
}
return value;
}
private _source: IIterator<T>;
private _step: number;
}

@@ -10,3 +10,2 @@ // Copyright (c) Jupyter Development Team.

|----------------------------------------------------------------------------*/
import { IIterator, iter, IterableOrArrayLike } from './iter';

@@ -16,3 +15,3 @@ /**

*
* @param object - The iterable or array-like object of interest.
* @param object - The iterable object of interest.
*

@@ -27,63 +26,24 @@ * @param count - The number of items to take from the iterable.

* contains an insufficient number of items.
*
* #### Example
* ```typescript
* import { take } from '@lumino/algorithm';
*
* let stream = take([5, 4, 3, 2, 1, 0, -1], 3);
*
* Array.from(stream); // [5, 4, 3]
* ```
*/
export function take<T>(
object: IterableOrArrayLike<T>,
export function* take<T>(
object: Iterable<T>,
count: number
): IIterator<T> {
return new TakeIterator<T>(iter(object), count);
}
/**
* An iterator which takes a fixed number of items from a source.
*/
export class TakeIterator<T> implements IIterator<T> {
/**
* Construct a new take iterator.
*
* @param source - The iterator of interest.
*
* @param count - The number of items to take from the source.
*/
constructor(source: IIterator<T>, count: number) {
this._source = source;
this._count = count;
): IterableIterator<T> {
if (count < 1) {
return;
}
/**
* Get an iterator over the object's values.
*
* @returns An iterator which yields the object's values.
*/
iter(): IIterator<T> {
return this;
const it = object[Symbol.iterator]();
let item: IteratorResult<T>;
while (0 < count-- && !(item = it.next()).done) {
yield item.value;
}
/**
* Create an independent clone of the iterator.
*
* @returns A new independent clone of the iterator.
*/
clone(): IIterator<T> {
return new TakeIterator<T>(this._source.clone(), this._count);
}
/**
* Get the next value from the iterator.
*
* @returns The next value from the iterator, or `undefined`.
*/
next(): T | undefined {
if (this._count <= 0) {
return undefined;
}
let value = this._source.next();
if (value === undefined) {
return undefined;
}
this._count--;
return value;
}
private _count: number;
private _source: IIterator<T>;
}

@@ -10,3 +10,3 @@ // Copyright (c) Jupyter Development Team.

|----------------------------------------------------------------------------*/
import { IIterator, iter, IterableOrArrayLike } from './iter';
import { every } from './iter';

@@ -16,3 +16,3 @@ /**

*
* @param objects - The iterable or array-like objects of interest.
* @param objects - The iterable objects of interest.
*

@@ -25,3 +25,3 @@ * @returns An iterator which yields successive tuples of values where

* ```typescript
* import { zip, toArray } from '@lumino/algorithm';
* import { zip } from '@lumino/algorithm';
*

@@ -33,58 +33,11 @@ * let data1 = [1, 2, 3];

*
* toArray(stream); // [[1, 4], [2, 5], [3, 6]]
* Array.from(stream); // [[1, 4], [2, 5], [3, 6]]
* ```
*/
export function zip<T>(...objects: IterableOrArrayLike<T>[]): IIterator<T[]> {
return new ZipIterator<T>(objects.map(iter));
}
/**
* An iterator which iterates several sources in lockstep.
*/
export class ZipIterator<T> implements IIterator<T[]> {
/**
* Construct a new zip iterator.
*
* @param source - The iterators of interest.
*/
constructor(source: IIterator<T>[]) {
this._source = source;
export function* zip<T>(...objects: Iterable<T>[]): IterableIterator<T[]> {
const iters = objects.map(obj => obj[Symbol.iterator]());
let tuple = iters.map(it => it.next());
for (; every(tuple, item => !item.done); tuple = iters.map(it => it.next())) {
yield tuple.map(item => item.value);
}
/**
* Get an iterator over the object's values.
*
* @returns An iterator which yields the object's values.
*/
iter(): IIterator<T[]> {
return this;
}
/**
* Create an independent clone of the iterator.
*
* @returns A new independent clone of the iterator.
*/
clone(): IIterator<T[]> {
return new ZipIterator<T>(this._source.map(it => it.clone()));
}
/**
* Get the next value from the iterator.
*
* @returns The next value from the iterator, or `undefined`.
*/
next(): T[] | undefined {
let result = new Array<T>(this._source.length);
for (let i = 0, n = this._source.length; i < n; ++i) {
let value = this._source[i].next();
if (value === undefined) {
return undefined;
}
result[i] = value;
}
return result;
}
private _source: IIterator<T>[];
}

@@ -905,2 +905,1 @@ /**

}
//# sourceMappingURL=array.d.ts.map

@@ -1,6 +0,5 @@

import { IIterator, IterableOrArrayLike } from './iter';
/**
* Chain together several iterables.
*
* @param objects - The iterable or array-like objects of interest.
* @param objects - The iterable objects of interest.
*

@@ -12,3 +11,3 @@ * @returns An iterator which yields the values of the iterables

* ```typescript
* import { chain, toArray } from '@lumino/algorithm';
* import { chain } from '@lumino/algorithm';
*

@@ -20,38 +19,5 @@ * let data1 = [1, 2, 3];

*
* toArray(stream); // [1, 2, 3, 4, 5, 6]
* Array.from(stream); // [1, 2, 3, 4, 5, 6]
* ```
*/
export declare function chain<T>(...objects: IterableOrArrayLike<T>[]): IIterator<T>;
/**
* An iterator which chains together several iterators.
*/
export declare class ChainIterator<T> implements IIterator<T> {
/**
* Construct a new chain iterator.
*
* @param source - The iterator of iterators of interest.
*/
constructor(source: IIterator<IIterator<T>>);
/**
* Get an iterator over the object's values.
*
* @returns An iterator which yields the object's values.
*/
iter(): IIterator<T>;
/**
* Create an independent clone of the iterator.
*
* @returns A new independent clone of the iterator.
*/
clone(): IIterator<T>;
/**
* Get the next value from the iterator.
*
* @returns The next value from the iterator, or `undefined`.
*/
next(): T | undefined;
private _source;
private _active;
private _cloned;
}
//# sourceMappingURL=chain.d.ts.map
export declare function chain<T>(...objects: Iterable<T>[]): IterableIterator<T>;

@@ -1,2 +0,1 @@

import { IIterator } from './iter';
/**

@@ -9,33 +8,9 @@ * Create an empty iterator.

* ```typescript
* import { empty, toArray } from '@lumino/algorithm';
* import { empty } from '@lumino/algorithm';
*
* let stream = empty<number>();
*
* toArray(stream); // []
* Array.from(stream); // []
* ```
*/
export declare function empty<T>(): IIterator<T>;
/**
* An iterator which is always empty.
*/
export declare class EmptyIterator<T> implements IIterator<T> {
/**
* Get an iterator over the object's values.
*
* @returns An iterator which yields the object's values.
*/
iter(): IIterator<T>;
/**
* Create an independent clone of the iterator.
*
* @returns A new independent clone of the iterator.
*/
clone(): IIterator<T>;
/**
* Get the next value from the iterator.
*
* @returns The next value from the iterator, or `undefined`.
*/
next(): T | undefined;
}
//# sourceMappingURL=empty.d.ts.map
export declare function empty<T>(): IterableIterator<T>;

@@ -1,6 +0,5 @@

import { IIterator, IterableOrArrayLike } from './iter';
/**
* Enumerate an iterable object.
*
* @param object - The iterable or array-like object of interest.
* @param object - The iterable object of interest.
*

@@ -13,3 +12,3 @@ * @param start - The starting enum value. The default is `0`.

* ```typescript
* import { enumerate, toArray } from '@lumino/algorithm';
* import { enumerate } from '@lumino/algorithm';
*

@@ -20,39 +19,5 @@ * let data = ['foo', 'bar', 'baz'];

*
* toArray(stream); // [[1, 'foo'], [2, 'bar'], [3, 'baz']]
* Array.from(stream); // [[1, 'foo'], [2, 'bar'], [3, 'baz']]
* ```
*/
export declare function enumerate<T>(object: IterableOrArrayLike<T>, start?: number): IIterator<[number, T]>;
/**
* An iterator which enumerates the source values.
*/
export declare class EnumerateIterator<T> implements IIterator<[number, T]> {
/**
* Construct a new enumerate iterator.
*
* @param source - The iterator of values of interest.
*
* @param start - The starting enum value.
*/
constructor(source: IIterator<T>, start: number);
/**
* Get an iterator over the object's values.
*
* @returns An iterator which yields the object's values.
*/
iter(): IIterator<[number, T]>;
/**
* Create an independent clone of the iterator.
*
* @returns A new independent clone of the iterator.
*/
clone(): IIterator<[number, T]>;
/**
* Get the next value from the iterator.
*
* @returns The next value from the iterator, or `undefined`.
*/
next(): [number, T] | undefined;
private _source;
private _index;
}
//# sourceMappingURL=enumerate.d.ts.map
export declare function enumerate<T>(object: Iterable<T>, start?: number): IterableIterator<[number, T]>;

@@ -1,6 +0,5 @@

import { IIterator, IterableOrArrayLike } from './iter';
/**
* Filter an iterable for values which pass a test.
*
* @param object - The iterable or array-like object of interest.
* @param object - The iterable object of interest.
*

@@ -13,3 +12,3 @@ * @param fn - The predicate function to invoke for each value.

* ```typescript
* import { filter, toArray } from '@lumino/algorithm';
* import { filter } from '@lumino/algorithm';
*

@@ -20,40 +19,5 @@ * let data = [1, 2, 3, 4, 5, 6];

*
* toArray(stream); // [2, 4, 6]
* Array.from(stream); // [2, 4, 6]
* ```
*/
export declare function filter<T>(object: IterableOrArrayLike<T>, fn: (value: T, index: number) => boolean): IIterator<T>;
/**
* An iterator which yields values which pass a test.
*/
export declare class FilterIterator<T> implements IIterator<T> {
/**
* Construct a new filter iterator.
*
* @param source - The iterator of values of interest.
*
* @param fn - The predicate function to invoke for each value.
*/
constructor(source: IIterator<T>, fn: (value: T, index: number) => boolean);
/**
* Get an iterator over the object's values.
*
* @returns An iterator which yields the object's values.
*/
iter(): IIterator<T>;
/**
* Create an independent clone of the iterator.
*
* @returns A new independent clone of the iterator.
*/
clone(): IIterator<T>;
/**
* Get the next value from the iterator.
*
* @returns The next value from the iterator, or `undefined`.
*/
next(): T | undefined;
private _index;
private _source;
private _fn;
}
//# sourceMappingURL=filter.d.ts.map
export declare function filter<T>(object: Iterable<T>, fn: (value: T, index: number) => boolean): IterableIterator<T>;

@@ -1,6 +0,5 @@

import { IterableOrArrayLike } from './iter';
/**
* Find the first value in an iterable which matches a predicate.
*
* @param object - The iterable or array-like object to search.
* @param object - The iterable object to search.
*

@@ -34,7 +33,7 @@ * @param fn - The predicate function to apply to the values.

*/
export declare function find<T>(object: IterableOrArrayLike<T>, fn: (value: T, index: number) => boolean): T | undefined;
export declare function find<T>(object: Iterable<T>, fn: (value: T, index: number) => boolean): T | undefined;
/**
* Find the index of the first value which matches a predicate.
*
* @param object - The iterable or array-like object to search.
* @param object - The iterable object to search.
*

@@ -68,7 +67,7 @@ * @param fn - The predicate function to apply to the values.

*/
export declare function findIndex<T>(object: IterableOrArrayLike<T>, fn: (value: T, index: number) => boolean): number;
export declare function findIndex<T>(object: Iterable<T>, fn: (value: T, index: number) => boolean): number;
/**
* Find the minimum value in an iterable.
*
* @param object - The iterable or array-like object to search.
* @param object - The iterable object to search.
*

@@ -98,7 +97,7 @@ * @param fn - The 3-way comparison function to apply to the values.

*/
export declare function min<T>(object: IterableOrArrayLike<T>, fn: (first: T, second: T) => number): T | undefined;
export declare function min<T>(object: Iterable<T>, fn: (first: T, second: T) => number): T | undefined;
/**
* Find the maximum value in an iterable.
*
* @param object - The iterable or array-like object to search.
* @param object - The iterable object to search.
*

@@ -128,7 +127,7 @@ * @param fn - The 3-way comparison function to apply to the values.

*/
export declare function max<T>(object: IterableOrArrayLike<T>, fn: (first: T, second: T) => number): T | undefined;
export declare function max<T>(object: Iterable<T>, fn: (first: T, second: T) => number): T | undefined;
/**
* Find the minimum and maximum values in an iterable.
*
* @param object - The iterable or array-like object to search.
* @param object - The iterable object to search.
*

@@ -158,3 +157,2 @@ * @param fn - The 3-way comparison function to apply to the values.

*/
export declare function minmax<T>(object: IterableOrArrayLike<T>, fn: (first: T, second: T) => number): [T, T] | undefined;
//# sourceMappingURL=find.d.ts.map
export declare function minmax<T>(object: Iterable<T>, fn: (first: T, second: T) => number): [T, T] | undefined;

@@ -18,2 +18,1 @@ export * from './array';

export * from './zip';
//# sourceMappingURL=index.d.ts.map
/**
* An object which can produce an iterator over its values.
*/
export interface IIterable<T> {
/**
* Get an iterator over the object's values.
*
* @returns An iterator which yields the object's values.
*
* #### Notes
* Depending on the iterable, the returned iterator may or may not be
* a new object. A collection or other container-like object should
* typically return a new iterator, while an iterator itself should
* normally return `this`.
*/
iter(): IIterator<T>;
}
/**
* An object which traverses a collection of values.
* Create an array from an iterable of values.
*
* #### Notes
* An `IIterator` is itself an `IIterable`. Most implementations of
* `IIterator` should simply return `this` from the `iter()` method.
*/
export interface IIterator<T> extends IIterable<T> {
/**
* Create an independent clone of the iterator.
*
* @returns A new independent clone of the iterator.
*
* #### Notes
* The cloned iterator can be consumed independently of the current
* iterator. In essence, it is a copy of the iterator value stream
* which starts at the current location.
*
* This can be useful for lookahead and stream duplication.
*/
clone(): IIterator<T>;
/**
* Get the next value from the iterator.
*
* @returns The next value from the iterator, or `undefined`.
*
* #### Notes
* The `undefined` value is used to signal the end of iteration and
* should therefore not be used as a value in a collection.
*
* The use of the `undefined` sentinel is an explicit design choice
* which favors performance over purity. The ES6 iterator design of
* returning a `{ value, done }` pair is suboptimal, as it requires
* an object allocation on each iteration; and an `isDone()` method
* would increase implementation and runtime complexity.
*/
next(): T | undefined;
}
/**
* A type alias for an iterable or builtin array-like object.
*/
export declare type IterableOrArrayLike<T> = IIterable<T> | ArrayLike<T>;
/**
* Create an iterator for an iterable object.
* @deprecated
*
* @param object - The iterable or array-like object of interest.
*
* @returns A new iterator for the given object.
* @returns A new array of values from the given object.
*
* #### Notes
* This function allows iteration algorithms to operate on user-defined
* iterable types and builtin array-like objects in a uniform fashion.
*/
export declare function iter<T>(object: IterableOrArrayLike<T>): IIterator<T>;
/**
* Create an iterator for the keys in an object.
*
* @param object - The object of interest.
*
* @returns A new iterator for the keys in the given object.
*
* #### Complexity
* Linear.
*
* #### Example
* ```typescript
* import { each, keys } from '@lumino/algorithm';
* import { toArray } from '@lumino/algorithm';
*
* let data = { one: 1, two: 2, three: 3 };
* let stream = [1, 2, 3, 4, 5, 6][Symbol.iterator]();
*
* each(keys(data), key => { console.log(key); }); // 'one', 'two', 'three'
* toArray(stream); // [1, 2, 3, 4, 5, 6];
* ```
*/
export declare function iterKeys<T>(object: {
readonly [key: string]: T;
}): IIterator<string>;
export declare function toArray<T>(object: Iterable<T>): T[];
/**
* Create an iterator for the values in an object.
* Create an object from an iterable of key/value pairs.
*
* @param object - The object of interest.
* @param object - The iterable or array-like object of interest.
*
* @returns A new iterator for the values in the given object.
* @returns A new object mapping keys to values.
*
* #### Complexity
* Linear.
*
* #### Example
* ```typescript
* import { each, values } from '@lumino/algorithm';
* import { toObject } from '@lumino/algorithm';
*
* let data = { one: 1, two: 2, three: 3 };
* let data: [string, number][] = [['one', 1], ['two', 2], ['three', 3]];
*
* each(values(data), value => { console.log(value); }); // 1, 2, 3
* toObject(data); // { one: 1, two: 2, three: 3 }
* ```
*/
export declare function iterValues<T>(object: {
readonly [key: string]: T;
}): IIterator<T>;
export declare function toObject<T>(object: Iterable<[string, T]>): {
[key: string]: T;
};
/**
* Create an iterator for the items in an object.
*
* @param object - The object of interest.
*
* @returns A new iterator for the items in the given object.
*
* #### Complexity
* Linear.
*
* #### Example
* ```typescript
* import { each, items } from '@lumino/algorithm';
*
* let data = { one: 1, two: 2, three: 3 };
*
* each(items(data), value => { console.log(value); }); // ['one', 1], ['two', 2], ['three', 3]
* ```
*/
export declare function iterItems<T>(object: {
readonly [key: string]: T;
}): IIterator<[string, T]>;
/**
* Create an iterator for an iterator-like function.
*
* @param fn - A function which behaves like an iterator `next` method.
*
* @returns A new iterator for the given function.
*
* #### Notes
* The returned iterator **cannot** be cloned.
*
* #### Example
* ```typescript
* import { each, iterFn } from '@lumino/algorithm';
*
* let it = iterFn((() => {
* let i = 0;
* return () => i > 3 ? undefined : i++;
* })());
*
* each(it, v => { console.log(v); }); // 0, 1, 2, 3
* ```
*/
export declare function iterFn<T>(fn: () => T | undefined): IIterator<T>;
/**
* Invoke a function for each value in an iterable.
*
* @param object - The iterable or array-like object of interest.
* @param object - The iterable object of interest.
*

@@ -184,7 +62,7 @@ * @param fn - The callback function to invoke for each value.

*/
export declare function each<T>(object: IterableOrArrayLike<T>, fn: (value: T, index: number) => boolean | void): void;
export declare function each<T>(object: Iterable<T>, fn: (value: T, index: number) => boolean | void): void;
/**
* Test whether all values in an iterable satisfy a predicate.
*
* @param object - The iterable or array-like object of interest.
* @param object - The iterable object of interest.
*

@@ -211,7 +89,7 @@ * @param fn - The predicate function to invoke for each value.

*/
export declare function every<T>(object: IterableOrArrayLike<T>, fn: (value: T, index: number) => boolean): boolean;
export declare function every<T>(object: Iterable<T>, fn: (value: T, index: number) => boolean): boolean;
/**
* Test whether any value in an iterable satisfies a predicate.
*
* @param object - The iterable or array-like object of interest.
* @param object - The iterable object of interest.
*

@@ -238,222 +116,2 @@ * @param fn - The predicate function to invoke for each value.

*/
export declare function some<T>(object: IterableOrArrayLike<T>, fn: (value: T, index: number) => boolean): boolean;
/**
* Create an array from an iterable of values.
*
* @param object - The iterable or array-like object of interest.
*
* @returns A new array of values from the given object.
*
* #### Example
* ```typescript
* import { iter, toArray } from '@lumino/algorithm';
*
* let data = [1, 2, 3, 4, 5, 6];
*
* let stream = iter(data);
*
* toArray(stream); // [1, 2, 3, 4, 5, 6];
* ```
*/
export declare function toArray<T>(object: IterableOrArrayLike<T>): T[];
/**
* Create an object from an iterable of key/value pairs.
*
* @param object - The iterable or array-like object of interest.
*
* @returns A new object mapping keys to values.
*
* #### Example
* ```typescript
* import { toObject } from '@lumino/algorithm';
*
* let data = [['one', 1], ['two', 2], ['three', 3]];
*
* toObject(data); // { one: 1, two: 2, three: 3 }
* ```
*/
export declare function toObject<T>(object: IterableOrArrayLike<[string, T]>): {
[key: string]: T;
};
/**
* An iterator for an array-like object.
*
* #### Notes
* This iterator can be used for any builtin JS array-like object.
*/
export declare class ArrayIterator<T> implements IIterator<T> {
/**
* Construct a new array iterator.
*
* @param source - The array-like object of interest.
*/
constructor(source: ArrayLike<T>);
/**
* Get an iterator over the object's values.
*
* @returns An iterator which yields the object's values.
*/
iter(): IIterator<T>;
/**
* Create an independent clone of the iterator.
*
* @returns A new independent clone of the iterator.
*/
clone(): IIterator<T>;
/**
* Get the next value from the iterator.
*
* @returns The next value from the iterator, or `undefined`.
*/
next(): T | undefined;
private _index;
private _source;
}
/**
* An iterator for the keys in an object.
*
* #### Notes
* This iterator can be used for any JS object.
*/
export declare class KeyIterator implements IIterator<string> {
/**
* Construct a new key iterator.
*
* @param source - The object of interest.
*
* @param keys - The keys to iterate, if known.
*/
constructor(source: {
readonly [key: string]: any;
}, keys?: string[]);
/**
* Get an iterator over the object's values.
*
* @returns An iterator which yields the object's values.
*/
iter(): IIterator<string>;
/**
* Create an independent clone of the iterator.
*
* @returns A new independent clone of the iterator.
*/
clone(): IIterator<string>;
/**
* Get the next value from the iterator.
*
* @returns The next value from the iterator, or `undefined`.
*/
next(): string | undefined;
private _index;
private _keys;
private _source;
}
/**
* An iterator for the values in an object.
*
* #### Notes
* This iterator can be used for any JS object.
*/
export declare class ValueIterator<T> implements IIterator<T> {
/**
* Construct a new value iterator.
*
* @param source - The object of interest.
*
* @param keys - The keys to iterate, if known.
*/
constructor(source: {
readonly [key: string]: T;
}, keys?: string[]);
/**
* Get an iterator over the object's values.
*
* @returns An iterator which yields the object's values.
*/
iter(): IIterator<T>;
/**
* Create an independent clone of the iterator.
*
* @returns A new independent clone of the iterator.
*/
clone(): IIterator<T>;
/**
* Get the next value from the iterator.
*
* @returns The next value from the iterator, or `undefined`.
*/
next(): T | undefined;
private _index;
private _keys;
private _source;
}
/**
* An iterator for the items in an object.
*
* #### Notes
* This iterator can be used for any JS object.
*/
export declare class ItemIterator<T> implements IIterator<[string, T]> {
/**
* Construct a new item iterator.
*
* @param source - The object of interest.
*
* @param keys - The keys to iterate, if known.
*/
constructor(source: {
readonly [key: string]: T;
}, keys?: string[]);
/**
* Get an iterator over the object's values.
*
* @returns An iterator which yields the object's values.
*/
iter(): IIterator<[string, T]>;
/**
* Create an independent clone of the iterator.
*
* @returns A new independent clone of the iterator.
*/
clone(): IIterator<[string, T]>;
/**
* Get the next value from the iterator.
*
* @returns The next value from the iterator, or `undefined`.
*/
next(): [string, T] | undefined;
private _index;
private _keys;
private _source;
}
/**
* An iterator for an iterator-like function.
*/
export declare class FnIterator<T> implements IIterator<T> {
/**
* Construct a new function iterator.
*
* @param fn - The iterator-like function of interest.
*/
constructor(fn: () => T | undefined);
/**
* Get an iterator over the object's values.
*
* @returns An iterator which yields the object's values.
*/
iter(): IIterator<T>;
/**
* Create an independent clone of the iterator.
*
* @returns A new independent clone of the iterator.
*/
clone(): IIterator<T>;
/**
* Get the next value from the iterator.
*
* @returns The next value from the iterator, or `undefined`.
*/
next(): T | undefined;
private _fn;
}
//# sourceMappingURL=iter.d.ts.map
export declare function some<T>(object: Iterable<T>, fn: (value: T, index: number) => boolean): boolean;

@@ -1,6 +0,5 @@

import { IIterator, IterableOrArrayLike } from './iter';
/**
* Transform the values of an iterable with a mapping function.
*
* @param object - The iterable or array-like object of interest.
* @param object - The iterable object of interest.
*

@@ -13,3 +12,3 @@ * @param fn - The mapping function to invoke for each value.

* ```typescript
* import { map, toArray } from '@lumino/algorithm';
* import { map } from '@lumino/algorithm';
*

@@ -20,40 +19,5 @@ * let data = [1, 2, 3];

*
* toArray(stream); // [2, 4, 6]
* Array.from(stream); // [2, 4, 6]
* ```
*/
export declare function map<T, U>(object: IterableOrArrayLike<T>, fn: (value: T, index: number) => U): IIterator<U>;
/**
* An iterator which transforms values using a mapping function.
*/
export declare class MapIterator<T, U> implements IIterator<U> {
/**
* Construct a new map iterator.
*
* @param source - The iterator of values of interest.
*
* @param fn - The mapping function to invoke for each value.
*/
constructor(source: IIterator<T>, fn: (value: T, index: number) => U);
/**
* Get an iterator over the object's values.
*
* @returns An iterator which yields the object's values.
*/
iter(): IIterator<U>;
/**
* Create an independent clone of the iterator.
*
* @returns A new independent clone of the iterator.
*/
clone(): IIterator<U>;
/**
* Get the next value from the iterator.
*
* @returns The next value from the iterator, or `undefined`.
*/
next(): U | undefined;
private _index;
private _source;
private _fn;
}
//# sourceMappingURL=map.d.ts.map
export declare function map<T, U>(object: Iterable<T>, fn: (value: T, index: number) => U): IterableIterator<U>;

@@ -1,2 +0,1 @@

import { IIterator } from './iter';
/**

@@ -19,42 +18,12 @@ * Create an iterator of evenly spaced values.

* to `1`.
*
* #### Example
* ```typescript
* import { range } from '@lumino/algorithm';
*
* let stream = range(2, 4);
*
* Array.from(stream); // [2, 3]
* ```
*/
export declare function range(start: number, stop?: number, step?: number): IIterator<number>;
/**
* An iterator which produces a range of evenly spaced values.
*/
export declare class RangeIterator implements IIterator<number> {
/**
* Construct a new range iterator.
*
* @param start - The starting value for the range, inclusive.
*
* @param stop - The stopping value for the range, exclusive.
*
* @param step - The distance between each value.
*/
constructor(start: number, stop: number, step: number);
/**
* Get an iterator over the object's values.
*
* @returns An iterator which yields the object's values.
*/
iter(): IIterator<number>;
/**
* Create an independent clone of the iterator.
*
* @returns A new independent clone of the iterator.
*/
clone(): IIterator<number>;
/**
* Get the next value from the iterator.
*
* @returns The next value from the iterator, or `undefined`.
*/
next(): number | undefined;
private _index;
private _length;
private _start;
private _stop;
private _step;
}
//# sourceMappingURL=range.d.ts.map
export declare function range(start: number, stop?: number, step?: number): IterableIterator<number>;

@@ -1,6 +0,5 @@

import { IterableOrArrayLike } from './iter';
/**
* Summarize all values in an iterable using a reducer function.
*
* @param object - The iterable or array-like object of interest.
* @param object - The iterable object of interest.
*

@@ -39,4 +38,3 @@ * @param fn - The reducer function to invoke for each value.

*/
export declare function reduce<T>(object: IterableOrArrayLike<T>, fn: (accumulator: T, value: T, index: number) => T): T;
export declare function reduce<T, U>(object: IterableOrArrayLike<T>, fn: (accumulator: U, value: T, index: number) => U, initial: U): U;
//# sourceMappingURL=reduce.d.ts.map
export declare function reduce<T>(object: Iterable<T>, fn: (accumulator: T, value: T, index: number) => T): T;
export declare function reduce<T, U>(object: Iterable<T>, fn: (accumulator: U, value: T, index: number) => U, initial: U): U;

@@ -1,2 +0,1 @@

import { IIterator } from './iter';
/**

@@ -13,10 +12,10 @@ * Create an iterator which repeats a value a number of times.

* ```typescript
* import { repeat, toArray } from '@lumino/algorithm';
* import { repeat } from '@lumino/algorithm';
*
* let stream = repeat(7, 3);
*
* toArray(stream); // [7, 7, 7]
* Array.from(stream); // [7, 7, 7]
* ```
*/
export declare function repeat<T>(value: T, count: number): IIterator<T>;
export declare function repeat<T>(value: T, count: number): IterableIterator<T>;
/**

@@ -31,43 +30,9 @@ * Create an iterator which yields a value a single time.

* ```typescript
* import { once, toArray } from '@lumino/algorithm';
* import { once } from '@lumino/algorithm';
*
* let stream = once(7);
*
* toArray(stream); // [7]
* Array.from(stream); // [7]
* ```
*/
export declare function once<T>(value: T): IIterator<T>;
/**
* An iterator which repeats a value a specified number of times.
*/
export declare class RepeatIterator<T> implements IIterator<T> {
/**
* Construct a new repeat iterator.
*
* @param value - The value to repeat.
*
* @param count - The number of times to repeat the value.
*/
constructor(value: T, count: number);
/**
* Get an iterator over the object's values.
*
* @returns An iterator which yields the object's values.
*/
iter(): IIterator<T>;
/**
* Create an independent clone of the iterator.
*
* @returns A new independent clone of the iterator.
*/
clone(): IIterator<T>;
/**
* Get the next value from the iterator.
*
* @returns The next value from the iterator, or `undefined`.
*/
next(): T | undefined;
private _value;
private _count;
}
//# sourceMappingURL=repeat.d.ts.map
export declare function once<T>(value: T): IterableIterator<T>;

@@ -1,2 +0,1 @@

import { IIterator } from './iter';
/**

@@ -11,9 +10,5 @@ * An object which can produce a reverse iterator over its values.

*/
retro(): IIterator<T>;
retro(): IterableIterator<T>;
}
/**
* A type alias for a retroable or builtin array-like object.
*/
export declare type RetroableOrArrayLike<T> = IRetroable<T> | ArrayLike<T>;
/**
* Create an iterator for a retroable object.

@@ -27,3 +22,3 @@ *

* ```typescript
* import { retro, toArray } from '@lumino/algorithm';
* import { retro } from '@lumino/algorithm';
*

@@ -34,40 +29,5 @@ * let data = [1, 2, 3, 4, 5, 6];

*
* toArray(stream); // [6, 5, 4, 3, 2, 1]
* Array.from(stream); // [6, 5, 4, 3, 2, 1]
* ```
*/
export declare function retro<T>(object: RetroableOrArrayLike<T>): IIterator<T>;
/**
* An iterator which traverses an array-like object in reverse.
*
* #### Notes
* This iterator can be used for any builtin JS array-like object.
*/
export declare class RetroArrayIterator<T> implements IIterator<T> {
/**
* Construct a new retro iterator.
*
* @param source - The array-like object of interest.
*/
constructor(source: ArrayLike<T>);
/**
* Get an iterator over the object's values.
*
* @returns An iterator which yields the object's values.
*/
iter(): IIterator<T>;
/**
* Create an independent clone of the iterator.
*
* @returns A new independent clone of the iterator.
*/
clone(): IIterator<T>;
/**
* Get the next value from the iterator.
*
* @returns The next value from the iterator, or `undefined`.
*/
next(): T | undefined;
private _index;
private _source;
}
//# sourceMappingURL=retro.d.ts.map
export declare function retro<T>(object: IRetroable<T> | ArrayLike<T>): IterableIterator<T>;

@@ -1,6 +0,5 @@

import { IterableOrArrayLike } from './iter';
/**
* Topologically sort an iterable of edges.
*
* @param edges - The iterable or array-like object of edges to sort.
* @param edges - The iterable object of edges to sort.
* An edge is represented as a 2-tuple of `[fromNode, toNode]`.

@@ -28,3 +27,2 @@ *

*/
export declare function topologicSort<T>(edges: IterableOrArrayLike<[T, T]>): T[];
//# sourceMappingURL=sort.d.ts.map
export declare function topologicSort<T>(edges: Iterable<[T, T]>): T[];

@@ -1,6 +0,5 @@

import { IIterator, IterableOrArrayLike } from './iter';
/**
* Iterate over an iterable using a stepped increment.
*
* @param object - The iterable or array-like object of interest.
* @param object - The iterable object of interest.
*

@@ -14,3 +13,3 @@ * @param step - The distance to step on each iteration. A value

* ```typescript
* import { stride, toArray } from '@lumino/algorithm';
* import { stride } from '@lumino/algorithm';
*

@@ -21,40 +20,5 @@ * let data = [1, 2, 3, 4, 5, 6];

*
* toArray(stream); // [1, 3, 5];
* Array.from(stream); // [1, 3, 5];
* ```
*/
export declare function stride<T>(object: IterableOrArrayLike<T>, step: number): IIterator<T>;
/**
* An iterator which traverses a source iterator step-wise.
*/
export declare class StrideIterator<T> implements IIterator<T> {
/**
* Construct a new stride iterator.
*
* @param source - The iterator of values of interest.
*
* @param step - The distance to step on each iteration. A value
* of less than `1` will behave the same as a value of `1`.
*/
constructor(source: IIterator<T>, step: number);
/**
* Get an iterator over the object's values.
*
* @returns An iterator which yields the object's values.
*/
iter(): IIterator<T>;
/**
* Create an independent clone of the iterator.
*
* @returns A new independent clone of the iterator.
*/
clone(): IIterator<T>;
/**
* Get the next value from the iterator.
*
* @returns The next value from the iterator, or `undefined`.
*/
next(): T | undefined;
private _source;
private _step;
}
//# sourceMappingURL=stride.d.ts.map
export declare function stride<T>(object: Iterable<T>, step: number): IterableIterator<T>;

@@ -116,2 +116,1 @@ /**

}
//# sourceMappingURL=string.d.ts.map

@@ -1,6 +0,5 @@

import { IIterator, IterableOrArrayLike } from './iter';
/**
* Take a fixed number of items from an iterable.
*
* @param object - The iterable or array-like object of interest.
* @param object - The iterable object of interest.
*

@@ -15,37 +14,12 @@ * @param count - The number of items to take from the iterable.

* contains an insufficient number of items.
*
* #### Example
* ```typescript
* import { take } from '@lumino/algorithm';
*
* let stream = take([5, 4, 3, 2, 1, 0, -1], 3);
*
* Array.from(stream); // [5, 4, 3]
* ```
*/
export declare function take<T>(object: IterableOrArrayLike<T>, count: number): IIterator<T>;
/**
* An iterator which takes a fixed number of items from a source.
*/
export declare class TakeIterator<T> implements IIterator<T> {
/**
* Construct a new take iterator.
*
* @param source - The iterator of interest.
*
* @param count - The number of items to take from the source.
*/
constructor(source: IIterator<T>, count: number);
/**
* Get an iterator over the object's values.
*
* @returns An iterator which yields the object's values.
*/
iter(): IIterator<T>;
/**
* Create an independent clone of the iterator.
*
* @returns A new independent clone of the iterator.
*/
clone(): IIterator<T>;
/**
* Get the next value from the iterator.
*
* @returns The next value from the iterator, or `undefined`.
*/
next(): T | undefined;
private _count;
private _source;
}
//# sourceMappingURL=take.d.ts.map
export declare function take<T>(object: Iterable<T>, count: number): IterableIterator<T>;

@@ -1,6 +0,5 @@

import { IIterator, IterableOrArrayLike } from './iter';
/**
* Iterate several iterables in lockstep.
*
* @param objects - The iterable or array-like objects of interest.
* @param objects - The iterable objects of interest.
*

@@ -13,3 +12,3 @@ * @returns An iterator which yields successive tuples of values where

* ```typescript
* import { zip, toArray } from '@lumino/algorithm';
* import { zip } from '@lumino/algorithm';
*

@@ -21,36 +20,5 @@ * let data1 = [1, 2, 3];

*
* toArray(stream); // [[1, 4], [2, 5], [3, 6]]
* Array.from(stream); // [[1, 4], [2, 5], [3, 6]]
* ```
*/
export declare function zip<T>(...objects: IterableOrArrayLike<T>[]): IIterator<T[]>;
/**
* An iterator which iterates several sources in lockstep.
*/
export declare class ZipIterator<T> implements IIterator<T[]> {
/**
* Construct a new zip iterator.
*
* @param source - The iterators of interest.
*/
constructor(source: IIterator<T>[]);
/**
* Get an iterator over the object's values.
*
* @returns An iterator which yields the object's values.
*/
iter(): IIterator<T[]>;
/**
* Create an independent clone of the iterator.
*
* @returns A new independent clone of the iterator.
*/
clone(): IIterator<T[]>;
/**
* Get the next value from the iterator.
*
* @returns The next value from the iterator, or `undefined`.
*/
next(): T[] | undefined;
private _source;
}
//# sourceMappingURL=zip.d.ts.map
export declare function zip<T>(...objects: Iterable<T>[]): IterableIterator<T[]>;

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc