augmentative-iterable
Advanced tools
Comparing version 1.5.8 to 1.5.9
## 1.5.8 | ||
## 1.5.9 | ||
* 758d9c6 fix: performance improvement on async iteration | ||
## v1.5.8 | ||
* 4dfed59 1.5.8 | ||
* b261fcd fix: optimizing augmentativeIterateIterable | ||
@@ -4,0 +7,0 @@ ## v1.5.7 |
@@ -17,32 +17,32 @@ 'use strict'; | ||
function stepResolveState( | ||
wrapper, | ||
actionResult, | ||
augmentList, | ||
) { | ||
if (wrapper.next !== augmentList.next) { | ||
const { type } = wrapper; | ||
if (type === YIELD) wrapper.result = actionResult; | ||
else if (!actionResult) wrapper.state = type; | ||
} | ||
if (wrapper.state === YIELD && wrapper.next) { | ||
const item = wrapper.next; | ||
wrapper.type = item.type; | ||
actionResult = item.action ? item.action(wrapper.result) : wrapper.result; | ||
} | ||
return actionResult; | ||
} | ||
function resolveState(augmentList, wrapper) { | ||
wrapper.next = augmentList; | ||
wrapper.state = YIELD; | ||
function resolveState(augmentList, value) { | ||
let next = augmentList; | ||
let state = YIELD; | ||
let type; | ||
function recursive(chain) { | ||
while (wrapper.next) { | ||
wrapper.currentAi = wrapper.next; | ||
wrapper.next = wrapper.next.next; | ||
chain = stepResolveState(wrapper, chain, augmentList); | ||
while (next) { | ||
next = next.next; | ||
if (next !== augmentList.next) { | ||
if (type === YIELD) value = chain; | ||
else if (!chain) { | ||
state = type; | ||
break; | ||
} | ||
} | ||
if (state === YIELD && next) { | ||
type = next.type; | ||
chain = next.action ? next.action(value) : value; | ||
} | ||
if (isPromiseLike(chain)) return chain.then(recursive); | ||
} | ||
return wrapper; | ||
switch (state) { | ||
case YIELD: | ||
return { | ||
done: false, | ||
value, | ||
}; | ||
case STOP: | ||
return end; | ||
}; | ||
}; | ||
@@ -52,15 +52,4 @@ return recursive(); | ||
async function asyncProcResolving(wrapper, resolving, asyncNext) { | ||
if (isPromiseLike(resolving)) await resolving; | ||
switch (wrapper.state) { | ||
case YIELD: | ||
return { | ||
done: false, | ||
value: wrapper.result, | ||
}; | ||
case STOP: | ||
return end; | ||
default: | ||
return asyncNext(); | ||
}; | ||
function asyncProcResolvingFactory(next) { | ||
return (result) => result.then((value) => value ? value : next()); | ||
} | ||
@@ -71,4 +60,3 @@ | ||
let i = -1 + offset; | ||
async function asyncNext() { | ||
const syncNext = () => { | ||
let keepGoing; | ||
@@ -78,14 +66,5 @@ do { | ||
while (++i < length) { | ||
const wrapper = { result: base[i] }; | ||
const resolving = resolveState(augmentList, wrapper); | ||
if (isPromiseLike(resolving)) await resolving; | ||
switch (wrapper.state) { | ||
case YIELD: | ||
return { | ||
done: false, | ||
value: wrapper.result, | ||
}; | ||
case STOP: | ||
return end; | ||
}; | ||
const result = resolveState(augmentList, base[i]); | ||
if (isPromiseLike(result)) return asyncProcResolving(result); | ||
if (result) return result; | ||
} | ||
@@ -96,26 +75,4 @@ } while (keepGoing); | ||
}; | ||
const asyncProcResolving = asyncProcResolvingFactory(syncNext); | ||
function syncNext() { | ||
let keepGoing; | ||
do { | ||
keepGoing = false; | ||
while (++i < length) { | ||
const wrapper = { result: base[i] }; | ||
const resolving = resolveState(augmentList, wrapper); | ||
if (isPromiseLike(resolving)) return asyncProcResolving(wrapper, resolving, asyncNext); | ||
switch (wrapper.state) { | ||
case YIELD: | ||
return { | ||
done: false, | ||
value: wrapper.result, | ||
}; | ||
case STOP: | ||
return end; | ||
}; | ||
} | ||
} while (keepGoing); | ||
return end; | ||
}; | ||
return { | ||
@@ -128,73 +85,35 @@ next: syncNext, | ||
const it = base[Symbol.asyncIterator] ? base[Symbol.asyncIterator]() : base[Symbol.iterator](); | ||
async function asyncNext() { | ||
let keepGoing; | ||
const syncNext = () => { | ||
let keepGoing = false; | ||
do { | ||
keepGoing = false; | ||
do { | ||
let next = it.next(); | ||
if (isPromiseLike(next)) next = await next; | ||
keepGoing = !next.done; | ||
if (offset > 0) offset--; | ||
else if (keepGoing) { | ||
const wrapper = { result: next.value }; | ||
const resolving = resolveState(augmentList, wrapper); | ||
if (isPromiseLike(resolving)) await resolving; | ||
switch (wrapper.state) { | ||
case YIELD: | ||
return { | ||
done: false, | ||
value: wrapper.result, | ||
}; | ||
case STOP: | ||
return end; | ||
}; | ||
} | ||
} while (keepGoing); | ||
const next = it.next(); | ||
if (isPromiseLike(next)) return next.then(asyncProcNext); | ||
keepGoing = !next.done; | ||
if (offset > 0) offset--; | ||
else if (keepGoing) { | ||
const result = resolveState(augmentList, next.value); | ||
if (isPromiseLike(result)) return asyncProcResolving(result); | ||
if (result) return result; | ||
} | ||
} while (keepGoing); | ||
return end; | ||
} | ||
}; | ||
const asyncProcResolving = asyncProcResolvingFactory(syncNext); | ||
async function asyncProcNext(next) { | ||
next = await next; | ||
if (offset > 0) { | ||
offset--; | ||
return asyncNext(); | ||
} else if (next.done) return end; | ||
const processNext = (next) => { | ||
if (next.done) return end; | ||
const result = resolveState(augmentList, next.value); | ||
if (isPromiseLike(result)) return asyncProcResolving(result); | ||
if (result) return result; | ||
return syncNext(); | ||
}; | ||
const wrapper = { result: next.value }; | ||
const resolving = resolveState(augmentList, wrapper); | ||
return asyncProcResolving(wrapper, resolving, asyncNext); | ||
} | ||
let asyncProcNext = offset > 0 ? (next) => { | ||
if (next.done) return end; | ||
offset--; | ||
if (offset <= 0) asyncProcNext = processNext; | ||
return syncNext(); | ||
} : processNext; | ||
function syncNext() { | ||
let keepGoing; | ||
do { | ||
keepGoing = false; | ||
do { | ||
const next = it.next(); | ||
if (isPromiseLike(next)) return asyncProcNext(next); | ||
keepGoing = !next.done; | ||
if (offset > 0) offset--; | ||
else if (keepGoing) { | ||
const wrapper = { result: next.value }; | ||
const resolving = resolveState(augmentList, wrapper); | ||
if (isPromiseLike(resolving)) return asyncProcResolving(wrapper, resolving, asyncNext); | ||
switch (wrapper.state) { | ||
case YIELD: | ||
return { | ||
done: false, | ||
value: wrapper.result, | ||
}; | ||
case STOP: | ||
return end; | ||
}; | ||
} | ||
} while (keepGoing); | ||
} while (keepGoing); | ||
return end; | ||
}; | ||
return { | ||
@@ -201,0 +120,0 @@ next: syncNext, |
@@ -57,15 +57,6 @@ 'use strict'; | ||
const it = base[Symbol.iterator](); | ||
const skipNext = function next() { | ||
do { | ||
offset--; | ||
if (it.next().done) return end; | ||
} while (offset > 0); | ||
this.next = finalNext; | ||
return this.next(); | ||
}; | ||
const finalNext = () => { | ||
let next; | ||
while (!(next = it.next()).done) { | ||
const result = resolveState(augmentList, next.value); | ||
let n; | ||
while (!(n = it.next()).done) { | ||
const result = resolveState(augmentList, n.value); | ||
if (result) return result; | ||
@@ -76,4 +67,13 @@ } | ||
}; | ||
let current = offset > 0 ? () => { | ||
do { | ||
offset--; | ||
if (it.next().done) return end; | ||
} while (offset > 0); | ||
current = finalNext; | ||
return current(); | ||
} : finalNext; | ||
return { | ||
next: offset > 0 ? skipNext : finalNext, | ||
next: () => current(), | ||
error: it.error ? it.error.bind(it) : undefined, | ||
@@ -80,0 +80,0 @@ return: it.return ? it.return.bind(it) : undefined, |
{ | ||
"name": "augmentative-iterable", | ||
"description": "This project is just a template for creation of new projects", | ||
"version": "1.5.8", | ||
"version": "1.5.9", | ||
"private": false, | ||
@@ -6,0 +6,0 @@ "author": { |
35790
719