mirror of
https://github.com/flynx/types.js.git
synced 2025-10-29 02:20:07 +00:00
minor tweaks and cleanup...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
fe1f39cba6
commit
40d08efc5c
19
Array.js
19
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'),
|
||||
|
||||
@ -178,6 +178,7 @@ function(func){
|
||||
var GeneratorMixin =
|
||||
module.GeneratorMixin =
|
||||
object.Mixin('GeneratorMixin', 'soft', {
|
||||
STOP: object.STOP,
|
||||
|
||||
gat: makeGenerator('gat'),
|
||||
at: function(i){
|
||||
|
||||
@ -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": {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user