Skip to content

Commit ca58e03

Browse files
committed
Refactor to ignore iterator return values
1 parent c55d5c0 commit ca58e03

2 files changed

Lines changed: 3 additions & 232 deletions

File tree

lib/node_modules/@stdlib/iter/pop/lib/main.js

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );
2424
var isFunction = require( '@stdlib/assert/is-function' );
2525
var isIteratorLike = require( '@stdlib/assert/is-iterator-like' );
26-
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
2726
var iteratorSymbol = require( '@stdlib/symbol/iterator' );
2827
var noop = require( '@stdlib/utils/noop' );
2928

@@ -100,28 +99,15 @@ function iterPop( iterator, clbk, thisArg ) {
10099
i += 1;
101100
if ( v.done ) {
102101
FLG = true;
103-
if ( hasOwnProp( v, 'value' ) ) {
104-
cb.call( thisArg, v.value );
105-
}
106-
return {
107-
'done': true
108-
};
102+
return v;
109103
}
110104
last = v.value;
111105
return next();
112106
}
113107
if ( v.done ) {
114108
FLG = true;
115-
out = {};
116-
if ( hasOwnProp( v, 'value' ) ) {
117-
cb.call( thisArg, v.value );
118-
out.value = last;
119-
out.done = false;
120-
} else {
121-
cb.call( thisArg, last );
122-
out.done = true;
123-
}
124-
return out;
109+
cb.call( thisArg, last );
110+
return v;
125111
}
126112
out = {
127113
'value': last,

lib/node_modules/@stdlib/iter/pop/test/test.js

Lines changed: 0 additions & 215 deletions
Original file line numberDiff line numberDiff line change
@@ -30,37 +30,6 @@ var noop = require( '@stdlib/utils/noop' );
3030
var iterPop = require( './../lib' );
3131

3232

33-
// FUNCTIONS //
34-
35-
function createIterator( arr ) {
36-
var len;
37-
var it;
38-
var i;
39-
40-
len = arr.length;
41-
i = -1;
42-
43-
it = {};
44-
it.next = next;
45-
46-
return it;
47-
48-
function next() {
49-
var out;
50-
i += 1;
51-
if ( i < len ) {
52-
out = {};
53-
out.value = arr[ i ];
54-
out.done = ( i === len-1 );
55-
return out;
56-
}
57-
return {
58-
'done': true
59-
};
60-
}
61-
}
62-
63-
6433
// TESTS //
6534

6635
tape( 'main export is a function', function test( t ) {
@@ -360,142 +329,6 @@ tape( 'the function returns an iterator protocol-compliant object (callback)', f
360329
}
361330
});
362331

363-
tape( 'the function returns an iterator protocol-compliant object (value+done)', function test( t ) {
364-
var expected;
365-
var values;
366-
var actual;
367-
var it;
368-
var i;
369-
370-
values = [ 1, 2, 3, 4 ];
371-
expected = [
372-
{
373-
'value': 1,
374-
'done': false
375-
},
376-
{
377-
'value': 2,
378-
'done': false
379-
},
380-
{
381-
'value': 3,
382-
'done': false
383-
},
384-
{
385-
'done': true
386-
}
387-
];
388-
389-
it = iterPop( createIterator( values ) );
390-
t.equal( it.next.length, 0, 'has zero arity' );
391-
392-
actual = [];
393-
for ( i = 0; i < expected.length; i++ ) {
394-
actual.push( it.next() );
395-
}
396-
t.deepEqual( actual, expected, 'returns expected values' );
397-
t.end();
398-
});
399-
400-
tape( 'the function returns an iterator protocol-compliant object (value+done; single element iterator)', function test( t ) {
401-
var expected;
402-
var values;
403-
var actual;
404-
var it;
405-
var i;
406-
407-
values = [ 1 ];
408-
expected = [
409-
{
410-
'done': true
411-
}
412-
];
413-
414-
it = iterPop( createIterator( values ) );
415-
t.equal( it.next.length, 0, 'has zero arity' );
416-
417-
actual = [];
418-
for ( i = 0; i < expected.length; i++ ) {
419-
actual.push( it.next() );
420-
}
421-
t.deepEqual( actual, expected, 'returns expected values' );
422-
t.end();
423-
});
424-
425-
tape( 'the function returns an iterator protocol-compliant object (value+done; two element iterator)', function test( t ) {
426-
var expected;
427-
var values;
428-
var actual;
429-
var it;
430-
var i;
431-
432-
values = [ 1, 2 ];
433-
expected = [
434-
{
435-
'value': 1,
436-
'done': false
437-
},
438-
{
439-
'done': true
440-
}
441-
];
442-
443-
it = iterPop( createIterator( values ) );
444-
t.equal( it.next.length, 0, 'has zero arity' );
445-
446-
actual = [];
447-
for ( i = 0; i < expected.length; i++ ) {
448-
actual.push( it.next() );
449-
}
450-
t.deepEqual( actual, expected, 'returns expected values' );
451-
t.end();
452-
});
453-
454-
tape( 'the function returns an iterator protocol-compliant object (value+done; callback)', function test( t ) {
455-
var expected;
456-
var values;
457-
var actual;
458-
var FLG;
459-
var it;
460-
var i;
461-
462-
values = [ 1, 2, 3, 4 ];
463-
expected = [
464-
{
465-
'value': 1,
466-
'done': false
467-
},
468-
{
469-
'value': 2,
470-
'done': false
471-
},
472-
{
473-
'value': 3,
474-
'done': false
475-
},
476-
{
477-
'done': true
478-
}
479-
];
480-
481-
it = iterPop( createIterator( values ), clbk );
482-
t.equal( it.next.length, 0, 'has zero arity' );
483-
484-
actual = [];
485-
for ( i = 0; i < expected.length; i++ ) {
486-
actual.push( it.next() );
487-
}
488-
t.deepEqual( actual, expected, 'returns expected values' );
489-
490-
t.equal( FLG, true, 'returns expected value' );
491-
t.end();
492-
493-
function clbk( v ) {
494-
FLG = true;
495-
t.equal( v, values[ values.length-1 ], 'returns expected value' );
496-
}
497-
});
498-
499332
tape( 'the function supports specifying the callback execution context', function test( t ) {
500333
var expected;
501334
var values;
@@ -544,54 +377,6 @@ tape( 'the function supports specifying the callback execution context', functio
544377
}
545378
});
546379

547-
tape( 'the function supports specifying the callback execution context (value+done)', function test( t ) {
548-
var expected;
549-
var values;
550-
var actual;
551-
var ctx;
552-
var it;
553-
var i;
554-
555-
values = [ 1, 2, 3, 4 ];
556-
expected = [
557-
{
558-
'value': 1,
559-
'done': false
560-
},
561-
{
562-
'value': 2,
563-
'done': false
564-
},
565-
{
566-
'value': 3,
567-
'done': false
568-
},
569-
{
570-
'done': true
571-
}
572-
];
573-
574-
ctx = {
575-
'FLG': false
576-
};
577-
it = iterPop( createIterator( values ), clbk, ctx );
578-
t.equal( it.next.length, 0, 'has zero arity' );
579-
580-
actual = [];
581-
for ( i = 0; i < expected.length; i++ ) {
582-
actual.push( it.next() );
583-
}
584-
t.deepEqual( actual, expected, 'returns expected values' );
585-
586-
t.equal( ctx.FLG, true, 'returns expected value' );
587-
t.end();
588-
589-
function clbk( v ) {
590-
this.FLG = true; // eslint-disable-line no-invalid-this
591-
t.equal( v, values[ values.length-1 ], 'returns expected value' );
592-
}
593-
});
594-
595380
tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) {
596381
var it;
597382
var r;

0 commit comments

Comments
 (0)