diff --git a/Array.js b/Array.js index d467228..afdf0e6 100644 --- a/Array.js +++ b/Array.js @@ -31,22 +31,7 @@ module.STOP = // Wrap .map(..) / .filter(..) / .reduce(..) / .. to support STOP... // -// NOTE: these add almost no overhead to the iteration. -// NOTE: these will not return a partial result if stopped. -// -/*/ XXX should these return a partial result on STOP? -// ...use generators to do this... -var stoppable = function(iter){ - return function(func){ - try { - return this[iter](...arguments) - } catch(err){ - if(err === STOP){ - return - } else if(err instanceof STOP){ - return err.value } - throw err } } } -/*/ +// NOTE: internally these are implemented as for-of loops... var stoppableList = function(iter){ return function(func){ return [...this.iter()[iter](...arguments)] } } @@ -56,7 +41,6 @@ var stoppableValue = function(iter, no_return=false){ return no_return ? undefined : res } } -//*/ // Equivalent to .map(..) / .filter(..) / .reduce(..) that process the @@ -504,6 +488,7 @@ object.Mixin('ArrayProtoMixin', 'soft', { // Stoppable iteration... // + // NOTE: internally these are generators... smap: stoppableList('map'), sfilter: stoppableList('filter'), sreduce: stoppableValue('reduce'), diff --git a/generator.js b/generator.js index 94725ab..5c69aff 100644 --- a/generator.js +++ b/generator.js @@ -178,6 +178,7 @@ function(func){ var GeneratorMixin = module.GeneratorMixin = object.Mixin('GeneratorMixin', 'soft', { + STOP: object.STOP, gat: makeGenerator('gat'), at: function(i){ diff --git a/package.json b/package.json index 01e9789..ec11328 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ig-types", - "version": "6.3.1", + "version": "6.3.2", "description": "Generic JavaScript types and type extensions...", "main": "main.js", "scripts": {