public
Created

  • Download Gist
expand.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
enumerableProto.expand = function(selector) {
var parent = this;
return enumerableCreate(function () {
var current, q = [parent], innerEnumerator;
return enumeratorCreate(
function () {
while (true) {
if (!innerEnumerator) {
if (q.length === 0) {
return false;
}
innerEnumerator = q.shift().getEnumerator();
}
if (innerEnumerator.moveNext()) {
current = innerEnumerator.getCurrent();
q.push(selector(current));
return true;
} else {
innerEnumerator.dispose();
innerEnumerator = undefined;
}
}
},
function () { return current; },
function () {
if (innerEnumerator) {
innerEnumerator.dispose();
}
}
);
});
};

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.